RaagaSudha
RaagaSudha

Reputation: 397

Setting the text to checkbox dynamically in android

I need to create checkboxes dynamically in android. I am getting the value in my code but unable to set that value to checkbox.

My Code:

CheckBox[] cbs = new CheckBox[20]; 
for(int k=0; k<stringList3.size(); k++)
{
 System.out.println("stringlist3 in for loop"+stringList3.get(0));
 arr = stringList3.get(k);
 cbs[k] = new CheckBox(getContext());
 System.out.println("arr values"+arr.get(0));
 System.out.println("arr values"+arr.get(1));
 System.out.println("arr values"+arr.get(2));
 cbs[k].setText((CharSequence) arr.get(2));
 Rl.addView(cbs[k]);
                 } 

Here when I am setting the value arr.get(2) to checkbox it is not setting ...please help me regarding this... Thanks in advance

Upvotes: 0

Views: 1397

Answers (1)

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

I don't know how you written remaining code, just check your code with below example.

Dynamically adding views to layout

I think in your code, the problem may be stringList3.size() returning more than 20, so that you are getting force close. Just check it once.

Upvotes: 1

Related Questions