Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving listview simple_list_item_multiple_choice checkbox state using an Array Adapter
    text
    copied!<p>I am new to programming for Android devices. I am trying to figure out how to save the checkboxes in my listview generated by using the simple_list_item_multiple_choice and Array Adapter. I would like to be able to save the state of the checkboxes so that when an user hits the back button to go to another checklist they can come back to this checklist and pickup where they left.</p> <p>Please, please, please help!! Code and/or explanation would be ideal.</p> <p>Code:</p> <pre><code>public class BeachBabyStuff extends Activity { String[] beachstuffbaby = new String[]{ "Beach Blanket or Mat", "Beach Towels", "Beach Umbrella", "Beach Chair", "Books / Magazines", "Radio", "Pen / Paper", "Tablet"}; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listview); // Getting the reference to the listview object of the layout ListView listView = (ListView) findViewById(R.id.listview); // The checkbox for the each item is specified by the layout android.R.layout.simple_list_item_multiple_choice ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_multiple_choice, beachstuffbaby); // Setting adapter to the listview listView.setAdapter(adapter); //Manage the onItemClick method listView.setOnItemClickListener(new OnItemClickListener() { private View view; public void onItemClick(AdapterView&lt;?&gt; ListView, View view, int position, long id) { CheckedTextView textView = (CheckedTextView)view; textView.setChecked(!textView.isChecked()); this.view = view; } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload