I'm trying to create a list with custom rows, but these rows are in fact CardViews. The CardViews have multiple textviews, half of which are user-set through a previous prompt, and an imageview:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/custom_card"
android:clipToPadding="false"
android:clipChildren="false"
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:clipToPadding="false"
android:clipChildren="false"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:divider="@android:color/transparent"
android:dividerHeight="0.0px"
android:elevation="8dp"
card_view:cardElevation="10dp"
card_view:cardPreventCornerOverlap="false">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/gameIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="200dp"
android:layout_marginTop="16dp"
android:contentDescription="Application Icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/nameDesc"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/roleDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="TextView"
android:textColor="@android:color/black"
app:layout_constraintStart_toEndOf="@+id/roleTitle"
app:layout_constraintTop_toBottomOf="@+id/rankDesc" />
<TextView
android:id="@+id/regionDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regionTitle" />
<TextView
android:id="@+id/rankTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/regionTitle"
tools:text="@string/rankTitle" />
<TextView
android:id="@+id/regionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="24dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/gameIcon"
tools:text="@string/regionTitle" />
<TextView
android:id="@+id/nameDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nameTitle" />
<TextView
android:id="@+id/roleTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rankDesc"
tools:text="@string/roleTitle" />
<TextView
android:id="@+id/rankDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rankTitle" />
<TextView
android:id="@+id/nameTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/nameTitle" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</RelativeLayout>
The ListView will be filled dynamically by pressing a button and filling a prompt with text. I don't expect more than 5 rows in the list, so I chose a ListView instead of the better RecyclerView (which I had some problems in understanding and implementing).
Is there a way to use an adapter that could accomplish this task? I tried this:
ArrayList<View> listItems = new ArrayList<>();
ArrayAdapter<View> adapter;
[...]
adapter = new ArrayAdapter<>(this, R.layout.cardview_item, listItems);
ListView list = findViewById(R.id.profile_list);
list.setAdapter(adapter);
But I got the following error:
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView