I have a ListView and I want to perform Drag and Drop on list items. I am Overridding a onTouch method which has two parameters
@Override pub
One way is to implement a custom Adapter which you use to populate your ListView. In the getView method of your Adapter you can call setOnClickListener on the view that you create, and add an item click listener that way.
There is some sample code of this in setOnClickListener of a ListView not working.
I have added item position in llItem tag
in Adapter:
public View getView(int position, View convertView, ViewGroup parent) {
...
llItem = (LinearLayout) rowView.findViewById(R.id.lItem);
llItem.setTag("" + position);
llItem.setOnTouchListener(itemTouch);
...
}
and the extracted item position from tag
OnTouchListener itemTouch = new OnTouchListener() {
private int position;
@Override
public boolean onTouch(View v, MotionEvent event) {
LinearLayout ll = (LinearLayout)v.findViewById(R.id.lItem);
String itemTag = ll.getTag().toString();
int itemPosition = Integer.parseInt(itemTag);
...
}
}