I have a CardView
inside a RecyclerView
designed as such:
Here is the code for the same:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/cv_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:fontFamily="@font/roboto"
android:text="@string/customer_feedback"
android:textColor="@color/grey_shadow"
android:textSize="12sp" />
<TableLayout
android:id="@+id/tbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:stretchColumns="3">
<TableRow>
<ImageView
android:id="@+id/cv_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_column="1"
android:layout_marginEnd="16dp"
android:contentDescription="@string/row_title_icon"
android:src="@drawable/ic_settings" />
<TextView
android:id="@+id/cv_title"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_column="2"
android:fontFamily="@font/roboto"
android:gravity="start"
android:text="Android"
android:textSize="16sp" />
<TextView
android:id="@+id/cv_title_data"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_column="3"
android:fontFamily="@font/open_sans"
android:gravity="center|end"
android:text="Nougat 7.2.1"
android:textSize="12sp" />
</TableRow>
<TableRow
android:id="@+id/tv_subtitle_row"
android:animateLayoutChanges="true"
android:visibility="visible">
<TextView
android:id="@+id/cv_subtitle"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_column="2"
android:layout_marginTop="12dp"
android:fontFamily="@font/roboto"
android:gravity="start"
android:text="Operating System"
android:textSize="14sp" />
<TextView
android:id="@+id/cv_subtitle_data"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_column="3"
android:layout_marginTop="12dp"
android:fontFamily="@font/open_sans"
android:gravity="end"
android:text="Build 23.4.10 7.2.1"
android:textSize="12sp" />
</TableRow>
</TableLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="2dp"
android:background="@color/lightGrey" />
<android.support.v7.widget.AppCompatButton
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/open_sans"
android:text="Expand"
android:textAllCaps="false"
android:textColor="@color/grey_shadow" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Here is my RecyclerView
Adapter:
public class SystemInfoAdapter extends RecyclerView.Adapter<SystemInfoAdapter.SystemInfoViewHolder> {
private Context mContext;
private List<CardData> systemInformation;
public class SystemInfoViewHolder extends RecyclerView.ViewHolder {
public TextView tvGroup;
public TextView tvTitle;
public TextView tvTitleValue;
public TextView tvSubtitle;
public TextView tvSubtitleValue;
public ImageView ivIcon;
public SystemInfoViewHolder(View itemView) {
super(itemView);
tvGroup = itemView.findViewById(R.id.cv_group);
tvTitle = itemView.findViewById(R.id.cv_title);
tvTitleValue = itemView.findViewById(R.id.cv_title_data);
tvSubtitle = itemView.findViewById(R.id.cv_subtitle);
tvSubtitleValue = itemView.findViewById(R.id.cv_subtitle_data);
ivIcon = itemView.findViewById(R.id.cv_icon);
}
}
public SystemInfoAdapter(Context mContext, List<CardData> systemInformation) {
this.mContext = mContext;
this.systemInformation = systemInformation;
}
@Override
public SystemInfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.cv_system_info, parent, false);
return new SystemInfoViewHolder(itemView);
}
@Override
public void onBindViewHolder(SystemInfoViewHolder holder, int position) {
CardData sysInfo = systemInformation.get(position);
holder.tvGroup.setText(sysInfo.getCvGroup());
holder.tvSubtitle.setText(sysInfo.getCvSubtitle());
holder.tvSubtitleValue.setText(sysInfo.getCvSubtitleData());
holder.tvTitle.setText(sysInfo.getCvTitle());
holder.tvTitleValue.setText(sysInfo.getCvTitleData());
holder.ivIcon.setImageDrawable(sysInfo.getCvTitleIcon());
}
@Override
public int getItemCount() {
return systemInformation.size();
}
}
Problem is, that both the tables (Table 1 in green and Table 2 in red) inside the CardView
will hav dynamic amount of rows. How can I achieve this without creating multiple Visibility.GONE
rows? My initial idea was to make several invisible rows and make the visible with the button click, but I realised this maybe a really ugly way to do it.
Thanks.