Android Creating Array Of Widgets In The Xml And Reading In Activity
In my project i have several TextBoxes which i have to fill dynmically. I have the values to be filled in a list, and i want to apply setText to the text boxes at the time of itera
Solution 1:
You would try using reflection:
for(int i = 0; condition;i++){
try {
int id = (Integer) R.id.class.getField("textbox"+i).get(null);
TextView textView = (TextView) findViewById(id);
textView.setText("i th text from your list");
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Post a Comment for "Android Creating Array Of Widgets In The Xml And Reading In Activity"