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
Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With