当我滚动recyclerview时。其中的项目会自动被点击。如何解决此问题。
这是我的recyclerview(OnItemTouchListner)。在自动滚动项目时 被点击
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View view=rv.findChildViewUnder(e.getX(),e.getY());
String profile=null;
if(view!=null){
int position=rv.getChildAdapterPosition(view);
try {
JSONObject jsonObject=new JSONObject(arrayList.get(position));
profile=jsonObject.getString("profile");
} catch (JSONException e1) {
e1.printStackTrace();
}
Intent intent=new Intent(getActivity(),ProfileActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle=new Bundle();
bundle.putInt("position",position+1);
bundle.putString("profile",profile);
intent.putExtras(bundle);
startActivity(intent);
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
答案 0 :(得分:0)
您可以使用
holder.yourLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
JSONObject jsonObject=new JSONObject(arrayList.get(position));
profile=jsonObject.getString("profile");
} catch (JSONException e1) {
e1.printStackTrace();
}
Intent intent=new Intent(getActivity(),ProfileActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle=new Bundle();
bundle.putInt("position",position+1);
bundle.putString("profile",profile);
intent.putExtras(bundle);
mContext.startActivity(intent);
}
});