您的位置:首页 > 其它

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;

验证了下,搞定。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: