I know this type of question is asked before here. I have tried both gesture detector :
wholelistview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
which detects only swipe(cannot get row position here).
similarly in getview:
public View getView(int position, View convertView, ViewGroup parent) {
//other stuff
convertview.setOnTouchListener(same as above);
}
but cannot detect swipe.
Any solution for this ??? I want only the row position on which swipe is made.
hanry what kind of errors do you get? I've implemented it and it works perectly. But instead of storing the position of the element I'm storing the view holder that among the others also have the model property. Remember that you have to check if the convertview isn't null. Take a look at the code:
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
Model m = filter.subItems.get(position);
if(m != null)
{
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowlayout, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.position = position; - here you can put your position.
view.setOnTouchListener(this.listener);
//assign whatever you like to the viewHolder - in most cases the model and inlated controls and then assign
} else {
view = convertView;
}
view.setTag(viewHolder);
}
and then
public boolean onTouch(View v, MotionEvent event) {
ViewHolder viewHolder = ((ViewHolder) v.getTag());
}
hop that helps. ps: If you don't know anything about view holders and tags I suugest to see there. And my approach has been described in the link that Frankenstein gave.