Récupération de la valeur d'un EditText
Bonjour,
Dans mon application, j'ai deux layout.
Par appuie sur un bouton, la valeur d'un EditText du second layout est bien mis à jour.
Par contre, je n'arrive pas à récupérer la valeur de cet EditText.
Merci d'avance pour votre aide,
Bernard
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public void valider(View v) //marche très bien
{
//Toast.makeText(this, "Clicked on Button", Toast.LENGTH_LONG).show();
setContentView(R.layout.secondscreen);
tv1 = (EditText) findViewById(R.id.edittextViewRejet); // This is fine
tv1.append(ListeMaj);
tv1.setText(ListeMaj);
Button button = (Button)findViewById(R.id.buttonSMS);
button.setFocusable(true);
button.setFocusableInTouchMode(true);
button.requestFocus();
}
public void updatesms(View v) // Ne marche pas
{
tv2 = (EditText) findViewById(R.id.edittextViewRejet);
String Chaine=tv2.getText().toString();
Toast.makeText(this, "Click updatesms : " + Chaine, Toast.LENGTH_LONG).show();
}
public void updatetel(View v) // Ne marche pas
{
tv2 = (EditText) findViewById(R.id.edittextViewRejet);
String Chaine=tv2.getText().toString();
Toast.makeText(this, "Click updatetel : " + Chaine, Toast.LENGTH_LONG).show();
} |
Dans le premier Layout :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<TextView
android:id="@+id/textViewSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Texte du SMS de rejet : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editTextSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:gravity="top" />
<Button
android:id="@+id/buttonValider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="valider"
android:text="Valider" /> |
et dans le second (secondscreen)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewRejet"
android:layout_width="match_parent"
android:layout_height="75dp"
android:text="Liste des numéros bloqués : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/edittextViewRejet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:gravity="top" />
<Button
android:id="@+id/buttonSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="updatesms"
android:text="Valider pour bloquer les SMS" />
<Button
android:id="@+id/buttonTEL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="updatetel"
android:text="Valider pour bloquer les Appels" />
</LinearLayout> |