0

In my android application i want to send the value of EditText from an Activity1 to Activity2 to be used there ..What can i do please??

//This is my first Activity

public class registrer extends Activity {
   EditText ET_USER_NAME,ET_USER_PASS,ET_USER_CONFIRM;
Button btsuivant;

@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrer);

    ET_USER_NAME=(EditText)findViewById(R.id.new_user_name);

    Intent intent = new Intent(this,CreerCV3.class);
    intent.putExtra("Key1", ET_USER_NAME.getText().toString());
  }}

// the CreerCV3

public class CreerCV3 extends Activity {

String user_name,user_pass,user_confirm;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_creer_cv3);
    Intent intent=getIntent();
    String s=intent.getStringExtra("Key1");
    TextView t=(TextView)findViewById(R.id.ob);
    t.setText(s);
     }}

//xml of the textviex

    android:id="@+id/ob" />

//xml of the editText (regiter)

seems like everthing is ok but when i run the app there is no text displayed.....

Oumayma Jaziri
  • 51
  • 1
  • 10
  • just get that editText value and pass it to your second activity using `Intent` – Uttam Panchasara Apr 23 '16 at 10:27
  • Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – Gauthier Apr 23 '16 at 13:10

3 Answers3

1

You can use intent and putextra() in your first activity like below:

in activity one:

EditText editText;
editText=(EditText) findViewById(R.id.new_user_name);

Intent intent = new Intent(this,activity2.class);
intent.putExtra("key",editText.getText().toString());
startActivity(intent);

in activity two:

Intent intent=getIntent();
String s=intent.getStringExtra("key");

Toast.makeText(this,s,Toast.LENGTH_SHORT).show();
0

In First Activity you can do like below...

Intent intent = new Intent ( FirstAcvity.this, SecondActivity.class ); 
intent.putExtra ( "TextBox", editText.getText().toString() );
startActivity(intent);

In second activity, use following...

Intent i = getIntent(); 
String text = i.getStringExtra ( "TextBox","" );

Hope this will help...

Maulik Dodia
  • 1,629
  • 2
  • 21
  • 48
  • If it help you, can you Up vote it or you can accept my answer. If it is very very helpful, you can do both of it.@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 11:13
  • Please when i did like this i tried to display the value of the 'new user_name' in the second activity !Nothing is happend – Oumayma Jaziri Apr 23 '16 at 11:34
  • Do you have TextView in second activity? If so, just do like below. `TextView tv=(TextView) findViewById(R.id.second_activity_textview_id); tv.setText(text);` Where **text** is a String variable in above my answer. – Maulik Dodia Apr 23 '16 at 11:37
  • i did this but nothing was displayed please check my code i will edit my question – Oumayma Jaziri Apr 23 '16 at 11:41
  • Just add your whole code with both **XML** and **JAVA** files.@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 11:43
  • You forgot to write `startActivity(intent);`@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 11:58
  • the problem that when i add startActivity The register activity is not shown again .. but the CreerCV3 actiivty is shown without displaying the value of the editText.. i dont understand the issue!! – Oumayma Jaziri Apr 23 '16 at 12:09
  • Do like below@OumaymaJaziri Add below lines to `onCreate()` method... `btsuivant = (Button) findViewById(R.id.btn_id); btsuivant.setOnClickListener(this);` Add this `implements View.OnClickListener` after `extends Activity` AND Add below method after `onCreate(){}` `@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_id: Intent intent = new Intent(this, CreerCV3.class); intent.putExtra("Key1", ET_USER_NAME.getText().toString()); startActivity(intent); break; } }` – Maulik Dodia Apr 23 '16 at 12:17
  • the problem is : when i click at the button bt_suivant i pass to a second activity(CreerCV2) where i enter the employee's information then i click at a second button (Suivant) to take me to the third activity (CreerCV3) in that activity i add other informations and press button Register .... To register the employee 's information (means the information that was coming from activity Resgister&CreerCV2& CreerCV3) i hope that my idea is clear and sorry for my bad English :) – Oumayma Jaziri Apr 23 '16 at 12:25
  • Go to below link where I have put all the details....[link is here](http://pastebin.com/SnjGAFa3)..@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 12:25
  • What are you trying to achieve basically? If you want to Register a user, you can simply ask user for his/her information in **First** activity. You do not need **Second** and **Third** activity.@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 12:31
  • You can use [Imgur](http://imgur.com/) for putting you screen shots. You can send me your project and tell me you requirement on [Wetransfer](https://www.wetransfer.com/). I will sort it out.@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 12:37
  • If I have helped you. Please, up vote my answer.@OumaymaJaziri – Maulik Dodia Apr 23 '16 at 12:54
0

Have you read the "Build your first app" section of android developers site? The task you are asking about is quite well explained there!

from http://developer.android.com/training/basics/firstapp/starting-activity.html

//build you intent to start the activity
Intent intent = new Intent(this, DisplayMessageActivity.class);
//take the text from your edittext
String message = yourEditText.getText().toString();
//add that text as an extra to the activity
intent.putExtra(EXTRA_MESSAGE, message);
//start the Activity
startActivity(intent);

that's all!!

Apperside
  • 3,542
  • 2
  • 38
  • 65