У меня есть task_layout.xml
, и я хотел добавить Программно это файл макета представления карты, который уже адаптирован с recyclerView, который так хорошо работает с командой <include>
в файле xml
Cardview_layout.xml, адаптированный с recyclerView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/CARD_VIEW"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="8dp"
android:layout_marginHorizontal="25dp"
android:elevation="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/LIST_NAME_TEXT_VIEW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Groceries"
android:fontFamily="@font/segoeuib"
android:textSize="21sp"
android:textColor="#000000" />
<!-- Here where i want to add the child layout -->
</RelativeLayout>
</android.support.v7.widget.CardView>
макет task_layout.xml
Я хочу добавить программно, и я много чего пробовал, и он всегда вылетал
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<CheckBox
android:id="@+id/CHECK_B0X_TASK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:allowUndo="true"
android:text="Task1"
android:textSize="17sp"
android:fontFamily="@font/segoeui"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/TEXT_CLOCK_TASK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9:00 AM"
android:textSize="17sp"
android:fontFamily="@font/segoeui"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
в основном упражнении я набрал, что, но все еще не работает, всегда происходит сбой приложения, даже если тег <include>
в файле xml работает
CardView cardView = findViewById(R.id.CARD_VIEW);
View child1 = LayoutInflater.from(this).inflate(R.layout.task_layout,null);
cardView.addView(child1);