Please don't mark it as a duplicate of this.
I am trying Collapsable CardView
but the last card when expanded doesn't push its content upwards, rather the user has to explicitly scroll down. I have tried the mentioned ways but all in vain. This is happening.
This might be achieved using some library but I don't prefer it. I think I need to get the position of the current card and then apply logic.
Here's my implementation of the Adapter:
public class RVAdapter extends RecyclerView.Adapter<MyViewHolder> {
private ArrayList<AppItem> appItemList;
private Context context;
RVAdapter(ArrayList<AppItem> appItemList, Context context) {
this.appItemList = appItemList;
this.context = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_list_item, parent, false);
return new MyViewHolder(layoutView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
final AppItem item = appItemList.get(position);
holder.description.setText(item.getDescription());
holder.title.setText(item.getTitle());
holder.appImage.setBackgroundResource(item.getImageID());
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
@Override
public int getItemCount() {
return this.appItemList.size();
}
}
The ViewHolder:-
class MyViewHolder extends RecyclerView.ViewHolder {
ImageView appImage;
TextView title;
TextView description;
Button button;
MyViewHolder(final View itemView) {
super(itemView);
this.appImage = itemView.findViewById(R.id.image);
this.title = itemView.findViewById(R.id.title);
this.description = itemView.findViewById(R.id.description);
this.button = itemView.findViewById(R.id.button);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout expandableView = view.findViewById(R.id.expandable_view);
expandableView.setVisibility(expandableView.getVisibility() == View.GONE ?
View.VISIBLE : View.GONE);
}
});
}
}