I have a recyclerview with linear layout manager and it contains different items. one of the items have a button that hides or display the nested layout of this items.
So I added something like 10 rows of the specific type, and when I click on specific item, it's nested layout is displayed, but I see that another item display it's own nested layout. Second try was to click on some button and scrolling, the nested layout was shown on a different items.
As you can see from the code, I tried to call the method - notifyDataSetChanged(), but it doesn't help. I know that there is expanded recycler view, but In my case I want to solve it without change the whole code..
The layout:
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
>
<TextView
android:id = "@+id/tv"
android:layout_height="wrap_content"
android:layout_width = "wrap_content"
android:text = "click on the button"
/>
<Button
android:id = "@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:layout_toRightOf="@+id/tv"
/>
<RelativeLayout
android:id = "@+id/nested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv"
android:visibility="gone"
>
<TextView
android:id = "@+id/tv1"
android:layout_height="wrap_content"
android:layout_width = "wrap_content"
android:text = "click on the button"
/>
</RelativeLayout>
</RelativeLayout>
The code in the adapter (onBind)
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position)
{
int type = getItemViewType(position);
ViewType viewType = ViewType.values()[type];
try
{
switch (viewType)
{
case VIEW1:
// code for view 1
break;
case VIEW2:
final ViewHolder viewHolder = (ViewHolder) holder;
viewHolder.tv.setText("TV1");
viewHolder.btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
viewHolder.nestedLayout.setVisibility(!isVisible ? View.VISIBLE : View.GONE );
viewHolder.isVisible = !viewHolder.isVisible;
// notifyDataSetChanged();
}
});
break;
}
}
catch (Exception e)
{
e.printStackTrace();
Log.d("ChatListAdapter","chat list adapter ioexception" + e.getMessage());
}
}