Reputation: 125
I am a beginner in the android studio. I have created a button which opens a new activity which shows the full details of a specific recycler view item. How I can make this on left swipe. I need on left swipe a new activity should be open and the extra values should be passed to it. Please help. My On click listener code
public void onItemClick(int position) {
Intent detailintent = new Intent(this, DetailActivity.class);
ExampleItem clickeditem = mExampleList.get(position);
detailintent.putExtra(EXTRA_URL, clickeditem.getmDate());
startActivity(detailintent);
}
Upvotes: 2
Views: 279
Reputation: 467
You should use OnTouchListener
for each item and check the swipe movement direction with 'MotionEvent` object for detecting right left swipe, check this link
Upvotes: 1
Reputation: 13569
You could override onTouchEvent like this:
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
break;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float deltaX = x2 - x1;
if (Math.abs(deltaX) > DISTANCE)
{
//do something
}
break;
}
return super.onTouchEvent(event);
}
x1
,x2
,and deltaX
are fields of activity class, such as:
private float x1,x2;
private final static int DISTANCE = 200;
Upvotes: 0