我已经尝试创建像 iphone 这样的列表视图,如果你轻扫让/向右,它会显示你删除按钮,如果你点击行,它会进入下一个活动,但我遇到了一些问题,我在检测列表视图行舔事件时遇到问题被点击或滑动
我的代码是
gestureListener = new View.OnTouchListener() {
private int padding = 0;
private int initialx = 0;
private int currentx = 0;
private adapHolder viewHolder;
public boolean onTouch(View v, MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_DOWN)
{
padding = 0;
initialx = (int) event.getX();
currentx = (int) event.getX();
viewHolder = ((adapHolder) v.getTag());
}
if ( event.getAction() == MotionEvent.ACTION_MOVE)
{
currentx = (int) event.getX();
padding = currentx - initialx;
if(viewHolder != null)
{
if(Math.abs(padding)>HORIZONTAL_MIN_DISTANCE){
viewHolder.btnDelete.setVisibility(View.VISIBLE);
viewHolder.imgArrow.setVisibility(View.GONE);
v.setPadding(padding, 0,0, 0);
//return true;
}
}
}
if ( event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL)
{
padding = 0;
initialx = 0;
currentx = 0;
v.setPadding(10, 0,0, 0);
}
return true;
}};
和我的列表视图点击事件,
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View rowView, int positon,long id) {
System.out.println("position :"+positon);
}
});
我在 getview 方法中为每一行设置了触摸监听器
convertView.setOnTouchListener(this.listener);
我的列表视图点击事件没有触发,我如何管理这两个事件
谢谢你