So, I have a card view created as follows:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
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/timeline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textStyle="bold" />
<TextView
android:id="@+id/website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
</LinearLayout>
And in my adapter class I have the following code to populate the card view.
public class MyViewHolder extends RecyclerView.ViewHolder {
private TextView tv_title, tv_timeline, tv_website;
public MyViewHolder(View view) {
super(view);
tv_title = (TextView) view.findViewById(R.id.title);
tv_timeline = (TextView) view.findViewById(R.id.timeline);
tv_website = (TextView) view.findViewById(R.id.website);
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.activity_row_data, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
holder.tv_title.setText(mTitleList.get(position));
holder.tv_timeline.setText(mtimelineList.get(position));
holder.tv_website.setText(mSiteSrc.get(position));
}
@Override
public int getItemCount() {
return mTitleList.size();
}
This correctly shows me the output I am expecting. The problem is that a CardView
only show me up to 3 items in my 3 TextView
, and then keep creating more cards holding up to 3 items to show me the rest.
What I would like to do is to use the textview "timeline" as a header, and then dynamically add content for textview "title" only. So for example, I might have a card which has 1 "timeline" TextView
, 0, 2, 5 etc "title" TextView
, 1 "website" TextView
Is this something that can be done with CardView? If yes, I'd appreciate any helpful pointers to help me get started.