Reputation: 3
Blockquote
pleas help me, i have activity aaa, bbb and ccc, in activity aaa i have data edittext, can i send data edittext from aaa to ccc?, but activity aaa intent to bbb and bbb intent to ccc
Blockquote
Upvotes: 0
Views: 678
Reputation: 1788
you need to reference your EditText
and get the text :
EditText et = (EditText) findViewById(R.id.my_edit_text);
String theText = et.getText().toString();
then pass it to another Activity
, you use an Intent
. for example :
Intent i = new Intent(this, MyNewActivity.class);
i.putExtra("text_label", theText);
startActivity(i);
In the new Activity in (onCreate()
), you get the Intent and retrieve the String, for example :
public class MyNewActivity extends Activity {
String string1;
@Override
protected void onCreate(...) {
...
Intent i = getIntent();
string1= i.getStringExtra("text_label");
}
}
Upvotes: 0
Reputation: 1642
You can achieve it using intents, do like this:
Intent intent = new Intent(this, ccc.class);
intent.putExtra("data from edittext", editText.getText().toString());
startActivity(intent);
Then in ccc class do this;
Intent intent = getIntent();
String dataFromaaa = intent.getStringExtra("data");
Upvotes: 0
Reputation: 333
After you reached the data of "aaa" edittext, you can create a variable that equals to what is in the edittext.
Then, you can use SharedPreferences to save the variable into a key, and then use this key on an other activity.
Create a variable named a , a==your edittext text.
then use this code to save "a" into a key:
SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
score = prefs.getInt("key", a);
and then at the other activity use this code to get "a":
SharedPreferences prefs = getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
int value = prefs.getInt("key", 0);
Upvotes: 1
Reputation: 912
use putExtra to pass arguments between activities:
Intent intent = new Intent(this, ccc.class);
intent.putExtra("EDIT_TEXT_DATA", editText.getText().toString());
startActivity(intent)
Upvotes: 0