[我在RecyclerView B
中放了另一个RecyclerView A
。我在外部RecyclerView A的适配器的OnClickListener
中设置了ItemView
。
当我在ItemView
中的RecyclerView A
上单击任何位置时,OnClickListener将正常工作,但是当我在RecyclerView B
中单击ItemView
时,我的OnClickListener
不再起作用。有谁知道为什么会这样?
解决此问题的最佳方法是将OnClickListener
赋予适配器的主要布局。
例如:-
<RelativeLayout
android:layout_above="@+id/mainlayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
............ //more layout.
</RelativeLayout>
然后在适配器中输入OnClickListener
。
holder.mainlayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Your code
}
});
这将起作用并解决您的问题。