给定onTouch
ListView
对象上motionEvent.getY()
获得的y坐标,如何根据onItemClickListener
确定项目所涉及的位置/索引?
不幸的是,我无法使用getListView().setOnTouchListener(listViewTouchListener);
View.OnTouchListener listViewTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d("test", "Y pos: " + motionEvent.getY());
}
};
。
{{1}}
答案 0 :(得分:5)
获得MotionEvent
对象后,您可以执行类似
private ListView list;
<some code to initialize ListView>
public int getPosition(MotionEvent e1){
int pos = list.pointToPosition((int)e1.getX(), (int)e1.getY());
Log.d("test","Position: "+pos);
return pos;
}