setOnItemClickListener VS setOnItemSelectedListener in ListView.

后端 未结 5 395
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 05:20

I wish to set an onClickListener on items of a ListView but I see two methods setOnItemClickListener and setOnItemSelectedListener . I didint find

相关标签:
5条回答
  • 2021-01-04 05:24

    Not necessarily true. You can have a ListView that will be navigable with the keyboard or accelerometer. Also clicking an item doesn't need to mean selecting it - maybe after selecting something once you want to block selection until some other event happens.

    For all purposes if you want to react to a selection of an item use the setOnItemSelectedListener but if you want to react to the user clicking on them go with setOnItemClickListener.

    0 讨论(0)
  • 2021-01-04 05:33

    Difference between these to methods is presented in their description:

    has been selected vs has been clicked
    

    Actually, the difference is just the same as one between selected and clicked in Android terms. Select it's more like highlight, please refer to more detailed explanation about selected state here (under android:state_selected). Click is the same as pressed in android terms and described under the same link but under android:state_pressed.

    0 讨论(0)
  • 2021-01-04 05:37

    I am not sure but it is my opinion.Might be wrong. setOnItemClickListener:Register a callback to be invoked when an item in this AdapterView has been clicked.It always return true.

    setOnItemSelectedListener:Register a callback to be invoked when an item in this AdapterView has been clicked.it return true and also false. If not selected any item then it will show nothing is selected.It is just force to user that select an option.Select an item and go next just kind of that. But when user forgot to select an item then if will remembered also user that he did not select any option.

    0 讨论(0)
  • 2021-01-04 05:47

    It is like

    the item is clicked (single selection) vs the item is selected (used in multiple selection)

    0 讨论(0)
  • 2021-01-04 05:47

    I think OnItemSelectedListener is invoked when an item in the list is selected using navigation keys of a keypad or by using tackball.

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