I have a LinearLayout in which I am adding some CheckBoxes dynamically, they are adding perfectly well on first call, when I am calling the same method with different values, then they are not appearing in that LinearLayout, old values are not getting replaced with new values.
I checked values in LogCat and they seem fine, whatever I’m passing is being displayed in LogCat but not appearing in LinearLayout.
Here’s my method that adds the view:
private void setOptions(int questionID2) {
ArrayList<String> options = pustakDB.getOptions(questionID2);
Log.e("optionsInAct", options.toString() + " size " + options.size());
OptionView = new LinearLayout(this);
OptionView.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, img.getId());
p.addRule(RelativeLayout.RIGHT_OF, questionNumber.getId());
rel.addView(OptionView, p);
int i = 0;
while (i < options.size()) {
CheckBox c = new CheckBox(this);
c.setText(options.get(i));
c.setId(i);
OptionView.addView(c);
i++;
}
}
Edit: “rel” here is RelativeLayout.
Try this and see if it works.