I'm working in Android studio and I set up a Text Field widget in my MainActivity class for the user to enter their name. When the use enters their name and clicks the login button I also set up, I want a "Hello, 'name'" string to appear. How do I pass the name input to the my SecondActivity.java class?
Asked
Active
Viewed 342 times
-5
-
use intent to pass data between activities – sinsuren Aug 02 '16 at 06:06
2 Answers
1
Textview textview = new (TextView)findViewById(R.id.text1)
TextView TV2 = new (TextView)findViewById(R.id.text2)
Button Login = new (Button)findViewByID(R.id.button1)
Login.setOnClickListener(new OnClickListener(...{
//Do anything you want to, like:
TV2.setText("Welcome " +textView.getText().toString() );
}
And when you want to pass data:
Intent i = new Intent(getApplicationContent, ....)
i.putExtra(String(then add textview.getText.toString()))
startActivity(i)
Hope this helps, but please google this next time

Ethan
- 1,905
- 2
- 21
- 50
-
@Kushan true, lets get rid of all of these comments, not very relevant :D – Ethan Aug 02 '16 at 06:22
1
Use an Intent:
Intent intent=new Intent(MainActivity.this,NextActivity.class);
intent.putExtra("name",youttextinput.getText().toString());
startActivity(intent);
You can then get it using:
String yourName=getIntent().getExtras().getString("name");

Kushan
- 5,855
- 3
- 31
- 45