I am trying to implement an appropriate behavior in my Android app if it runs on a device with dPad.
There is an activity with a ListView
. The selected item changes properly as a user presses dPad buttons. However, I am trying to set the selected item programatically at a certain point in my Java code. I can achieve this by
myListView.setSelection(position);
That is fine but how should I clear the selection? If no item is selected, the method myListView.getSelectedItemPosition()
returns -1
. However, I can't call myListView.setSelection(-1)
as negative values are ignored by this method.
What is the correct way to unset the selected item?
I am aware of many question on Stack Overflow talking about "selected item in a list view" but they are about radio buttons and single choice, not about dPad navigation.