listview 与activity的onTouchevent 冲突解决
2014-05-19 17:06
253 查看
在项目中有个listview中的下拉刷新需求,在activity中重写onTouchevent方法无效。
是因为点击事件被listview截取了,无法收到点击事件
具体的点击事件分发机制详见
/article/1562152.html
解决方法
activity implents OnouchListener
在onTouch方法中
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (mListView.getLastVisiblePosition() == mOnlineListAdapter.getCount()){
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
startY=motionEvent.getY();
break;
case MotionEvent.ACTION_UP:
endY=motionEvent.getY();
if(Math.abs(endY-startY)>200&&mOnlineListAdapter.getCount()<100&&
mOnlineListAdapter.getCount()%25==0){
updateLoadingBar(LOADING_NOW);
size+=25;
requestForFreshMusic(size);
}else if(Math.abs(endY-startY)>200&&mOnlineListAdapter.getCount()%25!=0){
updateLoadingBar(LOADING_FINISH);
}
break;
}
}
//此处一定是返回false,点击事件没有消费完全,需要向下分发
return false;
验证了下,搞定。
是因为点击事件被listview截取了,无法收到点击事件
具体的点击事件分发机制详见
/article/1562152.html
解决方法
activity implents OnouchListener
在onTouch方法中
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (mListView.getLastVisiblePosition() == mOnlineListAdapter.getCount()){
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
startY=motionEvent.getY();
break;
case MotionEvent.ACTION_UP:
endY=motionEvent.getY();
if(Math.abs(endY-startY)>200&&mOnlineListAdapter.getCount()<100&&
mOnlineListAdapter.getCount()%25==0){
updateLoadingBar(LOADING_NOW);
size+=25;
requestForFreshMusic(size);
}else if(Math.abs(endY-startY)>200&&mOnlineListAdapter.getCount()%25!=0){
updateLoadingBar(LOADING_FINISH);
}
break;
}
}
//此处一定是返回false,点击事件没有消费完全,需要向下分发
return false;
验证了下,搞定。
相关文章推荐
- activity中滑动手势和listview滑动冲突解决方法
- 解决ListView在Activity中的滑动冲突代码
- Android ListView 与 Activity 的 onTouchEvent 冲突
- scrollView嵌套listView,重新设置listview高度解决冲突,但打开activity之后,初始位置不是顶部解决方案
- Android ListView 与 Activity 的 onTouchEvent 冲突
- Android 解决ListView 和 ScrollView 共存冲突的问题(另一种解决方案)
- LinearLayoutForListView 解决Listview与SrocllView 不冲突
- [Android]ScrollView和ListView套用冲突的解决方法
- Android 解决ListView 和 ScrollView 共存冲突的问题
- Android 解决ListView 和 ScrollView 共存冲突的问题
- android 自定义ScrollView实现反弹效果(以及解决和ListView之间的冲突)
- 滚动条:解决ScrollView与ListView显示冲突问题
- Android 解决ListView 和 ScrollView 共存冲突的问题
- 简单描述ListView中使用GestureDetector冲突的解决办法
- ScrollView与ListView,GridView共存冲突解决办法 Android
- android 自定义ScrollView实现反弹效果(以及解决和ListView之间的冲突) .
- TabActivity,ActivityGroup,ExpandableListActivity,ListView联合使用问题解决。
- 解决Android布局中ScrollView与ListView的冲突
- Android 解决ListView 和 ScrollView 共存冲突的问题
- android在学习——activity关闭和dialog.dismiss冲突的解决(Activity has leaked window com.android.internal.policy.impl.PhoneWindow)