Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView no longer reacts to onclick after a call to setSelection()

In Zwitscher I have a ListView that displays a number of tweets. The user can then reload the timeline and if there are new tweets, the new list is loaded into the list adapter (plus some old ones) and I scroll to the end of the list via

listView.setSelection(x); 

where x is the number of the oldest tweets of the freshly loaded ones. This works very well. But unfortunately this "disables" the onItemClick() and onItemLongClick() handlers on the view. If I then (e.g. from a button) call

listView.setSelection(0);

The handlers for onItemClick() and onItemLongClick() are "enabled" again.

I've verified that the handlers are still set on the listView after the call to setSelection(x). And disabling that call to setSelection(x) also does not "disable" the handlers.

Any idea what I am doing wrong?

The full source is here: https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/TweetListActivity.java and the lines in question are in onPostExecute() on line 417

like image 894
Heiko Rupp Avatar asked Jan 02 '11 18:01

Heiko Rupp


People also ask

How to get data from ListView by clicking item on ListView?

Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });

Is ListView deprecated Android?

We've learned how to implement the ListView, bind the data with the adapter and how to improve scrolling using ViewHolder pattern. It's worth to mentioned that the ListView is a kind of deprecated because the RecyclerView was introduced with the API 21 (Android Lollipop).


1 Answers

I could not reproduce that. onItemClick() is called after any setSelection. Try to isolate the problem down by creating a test case that reproduces. If you succeed, I thing you should submit a bug to android.

like image 57
Oliv Avatar answered Nov 15 '22 06:11

Oliv