0

Please give me an idea on how will I retrieve or pass the value of my edittext in my Page1.xml to the edittext in my Page2.xml.

For example, I have entered 1234 in the edittext in Page1.xml, when I pressed the button (which will redirect to my page 2 as well as it will pass the current value of my edittext in Page1.xml), I will see the 1234 in my edittext on my Page2.xml

How will I do that? Can you give me an idea or cite some example? Thanks!

Kerv
  • 179
  • 1
  • 5
  • 15
  • By pages do you mean activities? – Sohaib Oct 05 '13 at 14:54
  • Yes. It is. I want to pass the content of my edittext in Page1.xml to the edittext of my Page2.xml when I clicked the button. – Kerv Oct 05 '13 at 14:56
  • possible duplicate of [How to pass object from one activity to another in Android](http://stackoverflow.com/questions/2736389/how-to-pass-object-from-one-activity-to-another-in-android) – C-- Oct 06 '13 at 07:40

4 Answers4

1

You need to use intents.

Here is some sample code

public class ActivityOne extends Activity {

private Bundle extras = new Bundle();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout);

    final EditText note = (EditText) findViewById(R.id.myText);
    Button btnSend = (Button) findViewById(R.id.btn_send);

    btnSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            extras.putString("text", note.getText().toString());
            Intent intent = new Intent(ActivityOne.this,
                    SecondActivity.class);
            intent.putExtras(extras);

            startActivity(intent);

        }
    });
}

} 

ActivityTwo

public class SecondActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout_2);

    TextView name = (TextView) findViewById(R.id.yourText2);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {

        name.setText(extras.getString("text"));

    }
    }
}
Radoslav
  • 1,446
  • 1
  • 16
  • 30
0

You need to get the string value from edittext use intent and pass the value to the other activity.

In Second Activity you need to retrieve the value and then set the same to edittext.

Example

How do you pass a string from one activity to another?

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

Using intents to pass from one activity to another would be your solution as I can guess.

intent.putExtra("STRING_I_NEED",editText.getText());

And in the receiving activity as

String newString;
Bundle extras;
if (savedInstanceState == null) {
      extras = getIntent().getExtras();
      if(extras == null) {
      newString= null;
      } else {
            newString= extras.getString("STRING_I_NEED");
      }
} else {
     newString= (String) savedInstanceState.getSerializable("STRING_I_NEED");
}
editText.setText(newString);

Sohaib
  • 4,556
  • 8
  • 40
  • 68
0

Use intents to pass values from one activity to other.

U can get value of the EditText in FirstActivity and save it in a String and with the help of intents on onClick of Button putExtra your String

eg.

In for FirstActivity

    butt.onClickListner
    {
    ...
   String editTextValue = editText.getText().toString();
    Intent i= new Intent(this,SecondActivity.class");
     i.putExtra("key",editTextValue );
    startActiivty(i);

    }

In your onCreate of SecondActivity

Bundle extras = getIntent().getExtras();
if(extras !=null) {
    String valueFromFirstActivity = extras.getString("Key");
   editText2.setText(valueFromFirstActivity );    //Set your editTextValue of first  
                                                  //activity in editText2 of                        
                                                  //second activity
}
Manishika
  • 5,478
  • 2
  • 22
  • 28
  • Still showing blank on my edittext on my Second Page. Even when i entered 1234 in the edittext in my 1st activity, it shows none when I click the button to redirect. – Kerv Oct 05 '13 at 15:40
  • I've edited my answer.Try it – Manishika Oct 05 '13 at 15:53