These are my requirements for an Android app:
- There is a file with lines of text and "x" as a "done" marker
- The text lines shall be shown in a list on the scren when the app starts
- Each listbox line shall have a checkbox
- Checkbox shall be initially marked if the "x" is found in the corresponding text line
- User may click the checkbox to change the "done" marker
- When the app exits, the current "done" states shall be written to the file
Or in short: A simple "todo list" which remembers the "done" state of each entry.
The problem is that after reading and inserting the text lines into the ListView, I call "setItemChecked" to set the initial "Done" state. This has no effect on the screen. All items are still marked "not done". If I call "isItemChecked" directly after setting it to "true", the answer is "false". So the "setItemChecked" call is ignored.
This is the code:
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
lv = (ListView) findViewById (R.id.List);
}
protected void onResume ()
{
super.onResume ();
ReadEntriesFromFile ();
adap = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, Entries);
lv.setAdapter (adap);
int i;
for (i=0; i<Entries.length; i+=1)
{
lv.setItemChecked (i, Checks[i]);
}
lv.invalidate ();
lv.invalidateViews ();
adap.notifyDataSetChanged ();
}
What am I doing wrong?
What I have tried:
If have found on the net that calling "invalidate", "invalidateViews" or "notifyDataSetChanged" should help, but they have no effect.