In my Android application, I have created a static list of checkboxes in xml. On click of a button, I am trying to create a new checkbox after the static checkbox.
But all the time, when i click the button, a new checkbox gets created in the top left corner. How to dynamically create the button after an already existing checkbox.
btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
CheckBox cb = new CheckBox(caseSheetForm.this);
cb.setLayoutParams(params);
cb.setText("New Checkbox");
RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativelayout);
rl.addView(cb);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Aucun commentaire:
Enregistrer un commentaire