Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckboxes not changing checked status in UI?
    primarykey
    data
    text
    <p>I have a ListView that I am trying to use with a checkable item list. I am calling the toggle() method on my list item class in the ArrayAdaptor, but the checkbox is not being ticked in the UI. However, I can confirm that the correct items <em>are</em> being selected in the UI, and that the "isChecked()" status reports back correctly--just the UI doesn't change at all. Are there any special methods I need to call to update the checkbox graphic for the UI?</p> <p>To put it another way--how do I programmatically tell the UI that a checkbox should show up as "checked"? It seems this should be a very simple process, but I've been having a lot of trouble finding this information.</p> <p>Code is as follows:</p> <p>For the item data class in the ArrayAdaptor:</p> <pre><code>public class SelectedItemData extends CheckedTextView { public String _item_name; public String getItemName() { return _item_name; } public void setItemName(String in_name) { _item_name = in_name; } // methods public SelectedItemData(Context context) { super(context); init(); } public void init() { this._item_name = "UNSET"; this.setChecked(false); } @Override public String toString() { return _item_name; } } </code></pre> <p>In the Activity class (located within the onCreate method):</p> <pre><code>_selectedItemsListView = (ListView) findViewById(R.id.selected_items_listview); _selectedItemsListView.setItemsCanFocus(false); _selectedItemsListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); _selectedItemsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; listview, View view, int position, long id) { @SuppressWarnings("unchecked") ArrayAdapter&lt;SelectedItemData&gt; itemsAdapter = (ArrayAdapter&lt;SelectedItemData&gt;)_selectedItemsListView.getAdapter(); SelectedItemData selectedItem = itemsAdapter.getItem(position); selectedItem.toggle(); Toast.makeText(view.getContext(), "Item " + selectedItem.getItemName() + " Selected!", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Is Item Checked? " + selectedItem.isChecked()); _selectedItemsListView.setAdapter(itemsAdapter); } }); </code></pre> <p>Any guidance on how to enable the UI to properly display that one of the items have been selected/checked would be great. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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