Working on my thesis I'm gettin a warning in LogCat that I think might affect my code.
I receive a JSON with some data and I have to bild a layout with checkbox and radiobutton (in RadioGroup) programmatically. Later I can vote this survey and here is my problem cause when I getChildAt() in my layout
if(child instanceof CheckBox)
doesn't work and I can't understand why.
Here is my code:
ll = (LinearLayout) findViewById(R.id.llSurvey); //OnCreate
/*Creating CheckBox*/
String votes = jObj.getString("votes");
String label = jObj.getString("label");
String usid = jObj.getString("USID");
if(uType.equals("multi")){
CheckBox cb = new CheckBox(SingleSurvey.this);
cb.setText(label + " (" + votes + ")");
cb.setId(s+1000);
ll.addView(cb);
Log.i("MULTI_TYPE", "usid: " + usid + " id: " + cb.getId());
}
s++;
/*Voting*/
LinearLayout llvs = (LinearLayout) findViewById(R.id.llSurvey);
for(int i = 0; i < llvs.getChildCount(); i++){
View child = llvs.getChildAt(i);
int p = child.getId();
Log.i("CHILD ID", "id: " + p);
if(child instanceof TextView){
continue;
}
else if(child instanceof CheckBox){
Log.i("INSTANCE OF CB", "usid: " + usid);
CheckBox cb = (CheckBox) child;
if(cb.isChecked()){
Log.i("CHECKBOX", "usid: " + usid);
int cbId = cb.getId();
usid = rb_usid[cbId];
}
}
//some other stuff
}
Aucun commentaire:
Enregistrer un commentaire