По нажатию кнопки должен добавляться card view в котором linear layout, в котором nested scroll, в котором coordinator layout.
Когда программно создаю card view и вставляю его через addview в linear layout, т.e addview(linear_layout) проект выдает ошибку и просит удалить (removeView) родителя дочернего элемента.
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Информация в интернете какая-то смазанная и её мало, что делать не понимаю.. Помогите пожалуйста, заранее благодарен
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="8dp"
app:strokeColor="#565656"
app:strokeWidth="2dp"
android:layout_marginBottom="8dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/outputWindow1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/result_name"
android:padding="10dp"
android:textColorHint="@color/colorWhite" />
</com.google.android.material.card.MaterialCardView>
Добавить в
<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.core.widget.NestedScrollView
android:id="@+id/nest"
android:layout_width="match_parent"
android:layout_height="550dp"
android:clipToPadding="true"
android:paddingBottom="70dp">
<LinearLayout
android:id="@+id/LinLay"
android:layout_width="match_parent"
android:layout_height="550dp"
android:orientation="vertical">
программно