pooja
pooja

Reputation: 107

How to pass edittext value to another activity's edittext?

My project's requirement is : edittext value is first entered by user and that same value will be visible in another activity's editext , which should be read only..

Upvotes: 5

Views: 38601

Answers (7)

Mukta
Mukta

Reputation: 1547

Hope this will help full for you.

This code for second activity where you want to show the Data from First Activity.

 String mUrl = getIntent().getStringExtra("LinkingWord");
 editTextURL.setText(getIntent().getStringExtra("LinkingWord"));

Don't forget to call EditText ID

  EditText editTextURL = findViewById(R.id.edit_url);

Easy Peasy

HappyCoding

Upvotes: 0

user10322018
user10322018

Reputation: 1

public EditText var_name; 

var_name=(EditText)findViewById(R.id.input_id);

publc void function_name(){
    Intent i=new Intent(this, class_name.class);
    String s=this.edittext_var_name.getString().toString();
    i.putExtra("var_name","s");
    startActivity(i);
    }`

Upvotes: 0

Ambati_prasanna_akhil
Ambati_prasanna_akhil

Reputation: 49

Basically its not a big deal to pass edittext value to textview present in other activity just follow 2steps....

PROCESS

  1. get two Activities(java classes)

  2. in first Activity take editview

  3. in second Activity take textview

  4. dont forget to create a button and set Onclicklister to it

  5. code the step2 in first activity inside button onclicklisten

  6. now code the step3 in second activity

  7. now run the code

    ((where "name" is indicated as a token to verify so maintain same char in both activities))

STEP1

1.Mainactivity.this//(Activity from where you should get the value)

EditText edittext=(EditText)findViewById(R.id.edittext);
Intent intent=new Intent(getApplicationContext(),Main2Activity.class);
intent.putExtra ( "name", ed1.getText().toString() );
startActivity(intent);

STEP2:

2.Main2activity//(Activity to where you should get the value)

Textview textview = (TextView) findViewById(R.id.textview);
Bundle bb;
bb=getIntent().getExtras();
textview.setText(bb.getString("name"));

Upvotes: 0

Raymond P
Raymond P

Reputation: 752

Based on Lucifer's answer you could use a TextView in the second activity:

First Activity:

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

Second Activity:

Intent i = getIntent();
tv.setText(i.getStringExtra("text"); //tv is the TextView

Upvotes: 0

Lucifer
Lucifer

Reputation: 29632

You can pass it using Intent's putExtra() method. try this way,

In First Activity,

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

Now, in second activity, use following code,

Intent i = getIntent(); 
String text = i.getStringExtra ( "TextBox","" ); 
// Now set this value to EditText 
secondEditText.setText ( text ); 
secondEditText.setEnable(false);

Upvotes: 8

Chintan Khetiya
Chintan Khetiya

Reputation: 16142

You can send N number of data from one activity to other activity like below :

Sneder : Current.java

Intent values = new Intent(Current.this, Destination.class);
//values.putExtra("KEY","VALUE");
values.putExtra("USER_NAME",user_name);
startActivity(values);
finish();

Receiver : Destination.java

String value = getIntent().getStringExtra("USER_NAME");

Upvotes: 0

Avinash Kumar Pankaj
Avinash Kumar Pankaj

Reputation: 1720

get the value of edit text by

String text = edit_text.getText.toString;

then pass it to other activity like

intent.putExtra("text", text);

In that activity get it onCreate through bundle like

Bundle extras = getExtra().getIntent();
String text = extras.getString("text");

now set this value in your edittext like

edit_text2.setText(text);

modify this code according to you.

Upvotes: 1

Related Questions