1
Hello, I have an Activity that has some Textview fields and right below I am putting some Edittext so that I want to change these fields I insert the data and click on the button and it automatically goes there and changes these Textviews for me but I am not able to find something like on the net...
So I did something but not right:
Activity Code
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/App_Theme_Meals_Background"
tools:context="meals.com.meals.activity.Activity.PerfilActivity">
<TextView
android:id="@+id/textViewNome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Nome"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="16dp"
android:layout_marginTop="34dp"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textViewEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Email"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="16dp"
android:layout_marginTop="7dp"
app:layout_constraintTop_toBottomOf="@+id/textViewNome" />
<TextView
android:id="@+id/TextViewTelefone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Telefone"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="16dp"
android:layout_marginTop="17dp"
app:layout_constraintTop_toBottomOf="@+id/textViewEmail" />
<TextView
android:id="@+id/textViewNumeroCartao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="NumeroCartão"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@+id/TextViewTelefone" />
<TextView
android:id="@+id/CodCartaoPerfil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Cod Cartão"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,MissingConstraints,RtlHardcoded"
tools:layout_editor_absoluteY="183dp" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Alterar Casdastro"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText,RtlHardcoded"
app:layout_constraintVertical_bias="0.414" />
<EditText
android:id="@+id/editTextNomePerfil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textColorHint="#ffffff"
android:layout_marginLeft="16dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,LabelFor,MissingConstraints,RtlHardcoded"
tools:layout_editor_absoluteY="274dp" />
<EditText
android:id="@+id/editTextMailPerfil"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textColorHint="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_editor_absoluteY="338dp"
tools:ignore="LabelFor,MissingConstraints,RtlHardcoded" />
<EditText
android:id="@+id/editTextTelefone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textColorHint="#ffffff"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_editor_absoluteY="399dp"
tools:ignore="LabelFor,MissingConstraints,RtlHardcoded" />
<EditText
android:id="@+id/editTextCartãoPerfil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:ems="10"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textColorHint="#ffffff"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
tools:ignore="HardcodedText,LabelFor,MissingConstraints,RtlHardcoded"
tools:layout_editor_absoluteY="458dp" />
<EditText
android:id="@+id/editTextCodCartaoPerfil"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="251dp"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textColorHint="#ffffff"
tools:layout_editor_absoluteY="458dp"
tools:ignore="LabelFor,MissingConstraints" />
<Button
android:id="@+id/buttonAlterarPerfil"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@color/App_Theme_Meals_colorPrimaryDark"
android:text="Alterar Perfil"
android:textColor="@color/common_google_signin_btn_text_dark_default"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="HardcodedText" />
I don’t know why I couldn’t put all the code so it follows an image of Activity (Just below Change Profile is the Edittext that I want to set them equal with Textview)
Now follow my attempt at code
public class Perfilactivity extends Appcompatactivity {
private DatabaseReference firebase;
private TextView Nome;
private TextView Email;
private TextView telefone;
private TextView NumeroCartão;
private TextView CodCard;
private EditText EditName;
private EditText EditEmail;
private EditText EditTelefone;
private EditText EditCartao;
private EditText EditCodCartao;
private Button Alterar;
public Editable nome = "Victor Roja Tavoni";
public Editable email = "[email protected]";
public Editable Telefone = "+5519997749701";
public Editable Cartão = "0000000000000000";
public Editable codCard = "123";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_perfil);
Nome = (TextView) findViewById(R.id.textViewNome);
Email = (TextView) findViewById(R.id.textViewEmail);
telefone = (TextView) findViewById(R.id.TextViewTelefone);
NumeroCartão = (TextView) findViewById(R.id.textViewNumeroCartao);
CodCard = (TextView) findViewById(R.id.CodCartaoPerfil);
EditName = (EditText) findViewById(R.id.editTextNomePerfil);
EditEmail = (EditText) findViewById(R.id.editTextMailPerfil);
EditTelefone = (EditText) findViewById(R.id.editTextTelefone);
EditCartao = (EditText) findViewById(R.id.editTextCartãoPerfil);
EditCodCartao = (EditText) findViewById(R.id.editTextCodCartaoPerfil);
Alterar = (Button) findViewById(R.id.buttonAlterarPerfil);
nome = "Victor Roja Tavoni";
email = "[email protected]";
Telefone = "+5519997749701";
Cartão = "0000000000000000";
codCard = "123";
Nome.setText("Nome: " + nome);
Email.setText("Email: " + email);
telefone.setText("Telefone: " + Telefone);
NumeroCartão.setText("Numero Cartão: " + Cartão);
CodCard.setText("Cod. Cartão: "+codCard);
Alterar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nome = EditName.getText();
email = EditEmail.getText();
Telefone = EditTelefone.getText();
Cartão = EditCartao.getText();
CodCard = EditCodCartao.getText();
}
});
}
}