Note that there are some explanatory texts on larger screens.

plurals
  1. POListView, Checkable items don't get checked on Android 1.6
    text
    copied!<p>My app is currently targeted at Android 1.6. It contains a ListView with <a href="http://developer.android.com/reference/android/widget/AbsListView.html#CHOICE_MODE_SINGLE" rel="nofollow noreferrer">CHOICE_MODE_SINGLE</a>. All the items implement <a href="http://developer.android.com/reference/android/widget/Checkable.html" rel="nofollow noreferrer">Checkable</a>. I am using <a href="http://developer.android.com/reference/android/widget/AbsListView.html#setItemChecked%28int,%20boolean%29" rel="nofollow noreferrer">setItemChecked(int position, boolean value)</a> to check/uncheck items as needed. It works as expected on Android 2.1, 2.2 and 2.3. On Android 1.6 however, no item gets checked.</p> <p>Code looks like this:</p> <pre><code>Integer checkedIndex = 0; // This is actually set from somewhere else. void updateCheckedItem() { int count = adapter.getCount(); for (int i = 0; i &lt; count; i++) { listView.setItemChecked(i, isChecked(i)); } // Here, we should have a checked item (unless checkedIndex was null) SparseBooleanArray checkedPositions = listView.getCheckedItemPositions(); int size = checkedPositions.size(); // On Android 1.6, size is 0 (wrong) // On Android 2.x, size is 1 (correct) // Another try... int checkedPosition = listView.getCheckedItemPosition(); // On Android 1.6, checkedPosition is INVALID_POSITION (-1), meaning nothing is checked (wrong) // On Android 2.x, checkedPosition is whatever checkedIndex is (correct) } boolean isChecked(int position) { return checkedIndex != null &amp;&amp; checkedIndex == position; } </code></pre> <p><a href="https://stackoverflow.com/questions/3215518/listview-not-checking-items-on-android-1-5">This question</a> resolved the problem by setting ListView's ChoideMode in code, not XML. I did that in code to begin with and putting it in XML made no difference for me. Problem still occurs.</p> <p>How can I make this work on Android 1.6?</p>
 

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