i’m pretty new to android-development and im trying to build a ListView with 8 items, that each have checkboxes. is set them up already, but i dont know how i can set one/several box beeing checked via retrieving key.value-pairs from a SharedPreferences.
i think im pretty close, but there is one or two lines of code missing 🙁
this my code in the onCreate-method:
lv = (ListView) findViewById(R.id.lvMain);
getPreferences(MODE_PRIVATE).edit().putString("Spiel4", "yes").commit();
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, lvItems));
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
for (int i=1;i<9;i++) {
tmpString = null;
tmpString = getPreferences(MODE_PRIVATE).getString("Spiel"+i,"");
if (tmpString.equals("yes")) {
// -----> MISSING LINE HERE <-----
Log.i(tag,"Spiel"+i+"-value is YES!");
}
}
p.s.: my first post, formatting tricked me 🙁
you can use
add this line on missing line 🙂