调用 setSelection() 后,ListView 不再对 onclick 做出反应 [英] ListView no longer reacts to onclick after a call to setSelection()

查看:20
本文介绍了调用 setSelection() 后,ListView 不再对 onclick 做出反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Zwitscher 中,我有一个 ListView 显示许多推文.然后用户可以重新加载时间线,如果有新推文,新列表将加载到列表适配器(加上一些旧的),然后我通过

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); 

其中 x 是新加载的推文中最旧的推文的数量.这非常有效.但不幸的是,这会禁用"视图上的 onItemClick()onItemLongClick() 处理程序.如果我然后(例如从按钮)调用

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);

onItemClick()onItemLongClick() 的处理程序再次启用".

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

我已经验证在调用 setSelection(x) 之后处理程序仍然设置在 listView 上.并且禁用对 setSelection(x) 的调用也不会禁用"处理程序.

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.

知道我做错了什么吗?

完整来源在这里:https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/TweetListActivity.java 和有问题的行在 onPostExecute() 第 417 行

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

推荐答案

我无法重现.onItemClick() 在任何 setSelection 之后被调用.尝试通过创建可重现的测试用例来隔离问题.如果你成功了,我认为你应该向 android 提交一个错误.

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.

这篇关于调用 setSelection() 后,ListView 不再对 onclick 做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆