Note that there are some explanatory texts on larger screens.

plurals
  1. POListView.getSelectedItemPosition() return 0 unexpectedly
    primarykey
    data
    text
    <p>My <code>Activity</code> have a <code>ListView</code> that contains <code>CheckedTextView</code>. Once an item is clicked, I use <code>setItemChecked(position, true)</code> to make the item to be hightlighted.</p> <p>However, when the activity is just started up, when I touch an item, the item in position 0 also be highlighted. I use <code>getSelectedItemPosition()</code> to check, even though it is in touch mode(<code>isinTouchMode</code> = true), it return 0 but not -1.</p> <p>After I scroll the <code>listView</code>, it work normally, <code>getSelectedItemPosition()</code> return -1 as expected.</p> <p>Why do this happen? I just want the activity to process in touch mode not input by key.</p> <p>If it cannot be avoided. Can I correct it? I used <code>ListView.setSelection(-1)</code> but it take no effect.</p> <p>Edit: I somehow solve the problem by delete some redundant code. I want an item at specify position in listView to show on the top of the listView and highlighted when activity start so I used below code:</p> <pre><code>ListView.setItemChecked(position, true); ListView.setSelectionFromTop(position, 0); </code></pre> <p>What redundant is (I used the same code twice):</p> <pre><code>ListViewAdapter.notifyDataSetInvalidated(); ListView.setItemChecked(position, true); ListView.setSelectionFromTop(position, 0); </code></pre> <p>Although I solve the problem, I still want to know what going on behind. Why do the position 0 is selected when I "touch" the listView twice?</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.
    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