1

I have a listview which conatins contact numbers as it's item.

I want that when the user performs leftswipe(swap in left direction) over a contact , the app will start calling that contact.

I want to know how to handle/detect left swipe and right swipe over a contact and how to detect on which item of list view swipe event is performed.

thanks

1

2 Answers 2

1

there is a tutorial on handling Gestures in Android. Check it!!

Sign up to request clarification or add additional context in comments.

Comments

0

Use the onFling() method to detect swipe and as far as detecting a swipe for a particula list itme is considered, you will have to provide your own adapter and override it's getView() method.
For eg

public class My_simple_adapter extends ArrayAdapter<String> //THIS IS THE CUSTOM ADAPTER { private final Context context; private final String[] values; public My_simple_adapter(Context context,String[] values,int[] pos) { super(context,R.layout.list_item,values); this.context=context; this.values=values; } @Override public View getView(int position,View convert_view,ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.MY_LAYTOUT, parent, false); // THE ABOVE MY_LAYOUT IS THE LAYOUT YOU WANT TO LOAD FOR EACH ROW OF THE LISTVIEW TextView textView = (TextView) rowView.findViewById(R.id.tv1); textView.setText(values[position]); //SUPPOSE rlt IS THE ID OF THE ABOVE MY_LAYOUT //then rlt.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { Log.d("test", "clicked!"); if(gestureDetector.onTouchEvent(event)) { Log.d("test", "gesture detected"); return true; } return false; } }); return rowView; } } 


This is the gestureDetector :

 SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener(){ @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { boolean result; //DECIDE UNDER WHAT SPEED OF SWIPING U WANT TO MAKE THE CALL ... ... return result; } @Override public boolean onDown(MotionEvent e) { return true; } }; //AND FINALLY final GestureDetector gestureDetector = new GestureDetector(simpleOnGestureListener); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.