我想要從列表項中獲取列表項的位置。請建議我們如何做到這一點。 我試圖得到如下:我想從列表項中獲取列表項位置
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
int adapterIndex = listView.pointToPosition((int) motionEvent.getX(),(int) motionEvent.getY());
int firstViewItemIndex = listView.getFirstVisiblePosition();
int viewIndex = adapterIndex - firstViewItemIndex;
pos = listView.pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
pos=pos-listView.getFirstVisiblePosition();
view.startDrag(null, shadowBuilder, view, 0);
return true;
}
}
但總是得到0
工程像魅力... thanx很多。它節省了我的時間 –