Android: List View Selected item -1

后端 未结 1 1981
傲寒
傲寒 2021-01-03 00:10

Im getting a -1 value when i try to get the selected item position on my listview that is already populated.

list.setOnItemClickListener
(
   new AdapterView         


        
相关标签:
1条回答
  • 2021-01-03 00:41

    That means there is no row selected. The documentation states that getSelectedItemPosition() returns:

    int Position (starting at 0), or INVALID_POSITION if there is nothing selected.

    And INVALID_POSITION is -1.

    Note that you are calling getSelectedItemPosition() from an OnClickListener. Click and selection are not necessarily related. Selection comes from using the D-pad or trackball to navigate the list contents. If the user taps on the screen (or clicks in the emulator), there will be no selection anymore, but there will still be a click event.

    The arg2 value you show is the position of the clicked-upon item in the list.

    0 讨论(0)
提交回复
热议问题