- I want to expand/collapse content like below image when I click on a item of RecyclerView.
- It's the same effect of the new Android recent calls history list. The options "CALL" and "DETAILS" or "SEND MESSAGE" are visible only when an item is selected.
- Image: Images
And here is My RecyclerViewAdapter Class, thanks you so much:
public class RecyclerViewAdapter extends RecyclerView.Adapter { Context mContext; List mData;
public RecyclerViewAdapter(Context mContext, List<Contact> mData) { this.mContext = mContext; this.mData = mData; } @NonNull @Override public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { View v; v = LayoutInflater.from(mContext).inflate(R.layout.item_contact, viewGroup, false); MyViewHolder viewHolder = new MyViewHolder(v); return viewHolder; } @Override public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int position) { myViewHolder.tvName.setText(mData.get(position).getName()); myViewHolder.tvFname.setText(mData.get(position).getFname()); myViewHolder.img.setImageResource(mData.get(position).getPhoto()); } @Override public int getItemCount() { return mData.size(); } public static class MyViewHolder extends RecyclerView.ViewHolder{ private TextView tvName; private TextView tvFname; private ImageView img; public MyViewHolder(@NonNull View itemView) { super(itemView); tvName = (TextView)itemView.findViewById(R.id.tvName); tvFname = (TextView)itemView.findViewById(R.id.tvFname); img = (ImageView)itemView.findViewById(R.id.img_contact); } }
}
Asked
Active
Viewed 114 times
0

Jason Momoa
- 123
- 8
-
Another way is to put the logic of expand/collapse in your ViewHolder class – Romain Goutte-Fangeas May 27 '19 at 15:05
-
one way would be to add another field to the data used by the adapter and based on that, hide / show the expanded view – William Reed May 27 '19 at 15:05
-
@@ Can you give me some code to more info – Jason Momoa May 27 '19 at 15:07
-
You can use expandable layout from this library into your item.xml to implement what you want https://github.com/cachapa/ExpandableLayout – Mr. Patel May 27 '19 at 15:10