recyclerView.addOnItemTouchListener(new MyListClickListener(getContext(), new MyListClickListener.ClickListener() { @Override public void onClick(View v, int position) {
TextView textView = (TextView) v.findViewById(R.id.title);
Fragment fragment = ((MyPagerAdapter) viewPager.getAdapter()).getFragment(1);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(fragment);
fragment.onDestroy();
ft.attach(fragment);
ft.commit();
comm.sendData(String.valueOf(textView.getText()));
viewPager.setCurrentItem(1);
}
}));
public class MyListClickListener implements RecyclerView.OnItemTouchListener {
private GestureDetector gestureDetector;
ClickListener clickListener;
public MyListClickListener(Context context, ClickListener clickListener){
this.clickListener = clickListener;
gestureDetector = new GestureDetector(context,new GestureDetector.SimpleOnGestureListener(){
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(),e.getY());
if(child!= null && clickListener!= null && gestureDetector.onTouchEvent(e)){
clickListener.onClick(child,rv.getChildPosition(child));
}
return true;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
public interface ClickListener {
void onClick(View v, int position);
}
}
you have just add two Lines in Recyclar item layout root view
I think you are looking for ripple effect. Just create one xml file (ripple.xml) in drawable & write this code inside
& just write two line in your another xml file in which you have declared recyclerview elements.
Like in my case i am having only TextView and in parent tag i am declaring these two lines
Finally the result:
See this video:
https://www.youtube.com/watch?v=qvVkDb7DqCk