0
I have an Activity that contains the cardView of the image at the end of the question that has 3 edittext. I was wondering how I can do so that when I click on some button, a new cardview with the same layout is added again, so I can recover your data. I tried to follow the directions on this one question, but I was unsuccessful.
The cardview is inside another Relativelayout and its layout is as follows:
<android.support.v7.widget.CardView
android:id="@+id/infoContato"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/infoCadastro"
android:layout_marginTop="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp">
<RelativeLayout
android:id="@+id/tituloInfoContato"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/imageViewIcTelefone"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:contentDescription="@string/dicaTelefone"
android:src="@drawable/ic_phone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_toEndOf="@+id/imageViewIcTelefone"
android:layout_toRightOf="@+id/imageViewIcTelefone"
android:text="@string/lblInfoContato"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
<!-- Telefone -->
<android.support.design.widget.TextInputLayout
android:id="@+id/txtInputAddCadastroTelefone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tituloInfoContato">
<EditText
android:id="@+id/edtaddTelefone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dicaTelefone"
android:inputType="phone"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<!-- Celular -->
<android.support.design.widget.TextInputLayout
android:id="@+id/txtInputAddCadastroCelular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtInputAddCadastroTelefone">
<EditText
android:id="@+id/edtaddCelular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/dicaCelular"
android:inputType="phone"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<!-- Email -->
<android.support.design.widget.TextInputLayout
android:id="@+id/txtInputAddEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtInputAddCadastroCelular">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:hint="@string/Email"
android:inputType="textEmailAddress"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
Could you post the code that you performed and didn’t work? I see that your layout will be much simpler if you change the
RelativeLayout
external by aLinearLayout
withorientation="vertical"
, may even make it easier to addViews
dynamically.– Wakim
I tried this
View view=LayoutInflater.from(getApplicationContext()).inflate(R.layout.bloco_cardview, null);
RelativeLayout layout = (RelativeLayout)findViewById(R.id.layout_contato);
layout.addView(view);

– Rafael
I redid the code using a
LinearLayout
as the most external layout as you said, worked, now just need to figure out how to recover the data entered in edittext :)– Rafael
In that case just keep the reference
– Wakim
I am seeing how to do this right now, if you have any tips thank you.
– Rafael
I think I got it, every time I add a new block, I add his edittexts into one
ArrayList<EditText>
, then to receive the amount recovered by Arraylist.– Rafael