setSelectionAfterHeaderView()、setSelection()无法回到顶部
来源:互联网 发布:外卖软件开发 编辑:程序博客网 时间:2024/06/16 22:56
使用时发现setSelectionAfterHeaderView()、setSelection()有时候能够使listveiw回到顶部,但有时候却并没有到达顶部。能够回到顶部的场景是在输入框中输入搜索的内容进行搜索,listview数据更新回到顶部位置,其它情况下无法回到顶部。
查了下文档,文档中说明setSelectionAfterHeaderView()、setSelection()在touch mode的时候不起作用。
当用户开始使用触摸屏与设备交互的时候,设备就进入Touch Mode模式。当用户开始通过键盘与设备交互的时候,设备退出Touch Mode模式。
处理方式:
list.clearFocus();
list.post(new Runnable() { @Override public void run() { mListView.setSelectionAfterHeaderView(); }});
还有一种方式:
list.setAdapter(adapter); list.setSelectionAfterHeaderView();
两种方式的区别在于,使用第一种方式会继续响应事件,使用第二种方式相当于reset。比如进行滑动时点击回到顶部,第一种方式回到顶部滑动继续,第二种方式滑动事件会丢弃。
0 0
- setSelectionAfterHeaderView()、setSelection()无法回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- “回到顶部”
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 回到顶部
- 怎样编辑操作PDF文件
- 国外大神分享:给程序员的实用编程7+1条小贴士
- Xcode中的Release、Debug、Archive、Profile、Analyze
- 【Get深一度】香农定理(Shannon Theory)
- 红黑树
- setSelectionAfterHeaderView()、setSelection()无法回到顶部
- 问题 android.content.res.Resources$NotFoundException: String resource ID #0xfffffffa
- 多线程基础
- 学习项目代码总结(一)—— ListView的自定义Adapter的性能提升与注意事项
- android UI——分组+悬停 listview
- 第一次机房收费系统——写给自己
- LeetCode 115 Distinct Subsequences--In C++
- iOS开发:九宫格灵活布局
- jquery中如何防止冒泡事件