-5

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?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sharmi
  • 13
  • 1
  • 2

2 Answers2

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
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