So I'm trying to populate a ListView with Checkboxes. While my code does populate the ListView with the correct number of Checkboxes, the text for each textbox is incorrect (it appears to be the raw code for the Checkbox). What am I doing wrong?
Result:
Code for populating a checkbox: (SUBJECTS is an array of strings)
lv = (ListView) findViewById(R.id.myListView);
ArrayList<CheckBox> your_array_list = new ArrayList<CheckBox>();
int i = 0;
for (i = 0; i < 3; ++i) {
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText(SUBJECTS[i]);
your_array_list.add(cb);
}
ArrayAdapter<CheckBox> arrayAdapter = new ArrayAdapter<CheckBox (this, R.layout.cbview, your_array_list );
lv.setAdapter(arrayAdapter);
XML code for cbview:
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox"
xmlns:android="http://ift.tt/nIICcg" />
Aucun commentaire:
Enregistrer un commentaire