2 z741296320 z741296320 于 2014.07.22 11:02 提问

ListView的item的onTouch()返回true,在ListView的onTouch()还能接收到触摸事件?

我的想法是子view(就是ListView的item)中onTouch()返回true,那么ListView就应该接收不到MotionEvent,也就不能滚动了,而事实并非如此,不知道原因。

public class MainActivity extends ActionBarActivity {
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.listView1);
mListView.setAdapter(new MyListAdapter());
mListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("test", "onTouch");
return false;
}
});
}

private class MyListAdapter extends BaseAdapter {
    @Override
    public int getCount() {
        return 20;
    }
    @Override
    public Object getItem(int position) {
        return null;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            //R.layout.item_view布局文件中就只有一个LinearLayout,高60dp
            convertView = getLayoutInflater().inflate(R.layout.item_view, parent, false);
            convertView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // 返回为 true
                    return true;
                }
            });
        }
        return convertView;
    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!