0

There is Two Edit Texts Like Username and Password and one login Button..My Requirement is if we Enter user name and password are same or Different and press Button.Using Intent This Two String values in Edit texts Call in to another Activity and Display the Username and Password..Any One can show Example programme

I want this one also i m taking Intent in if condition (!username.equals(password))..it will pressed on login button it shows two text views as usernames.Ex:username Kumar,password: anil it shows only password as a text

Anilkumar
  • 47
  • 1
  • 8

3 Answers3

0

You need put them in Extras (putExtras) and then pass from the current activity to the other one.

You need capture your EditText value as String and then putExtra with Key - one each for your need and then retrieve them in the second activity.

You find on how to do this at - How to pass edit text data in form of string to next activity?

Community
  • 1
  • 1
Natarajan Raman
  • 606
  • 1
  • 4
  • 14
0

See below code

EditText et_username = (EditText) findViewById(R.id.edit_text1);
EditText et_password = (EditText) findViewById(R.id.edit_text2);
String username = et_username.getText().toString();
String password = et_password.getText().toString();

Now pass data at on click event in set below code.

Intent i = new Intent(this, Next.class);
i.putExtra("usename", username);
i.putExtra("password", password);
startActivity(i);

In next Activity in set below code:

public class Next extends Activity {

    String usename;
    String password;

    @Override
    protected void onCreate(...) {

        ...

        Intent i = getIntent();
        username= i.getStringExtra("username");
        password= i.getStringExtra("password");

       TextView tv_username = (TextView ) findViewById(R.id.text_view1);
       TextView tv_password = (TextView ) findViewById(R.id.text_view2);

         tv_username.setText(username.toString());
         tv_username.setText(password.toString());

    }
}
Ravi Vaghela
  • 3,420
  • 2
  • 23
  • 51
  • Here Where is Text Views In second Activity I want calling string values in edit texts to text view in another activity – Anilkumar Mar 23 '16 at 07:51
  • @Anilkumar now complete or not? – Ravi Vaghela Mar 23 '16 at 07:59
  • not get it ya..i want this one also i m taking Intent in if condition (!username.equals(password))..it will pressed on login button it shows two text views as usernames.Ex:username Kumar , password: anil it shows only password as a text – Anilkumar Mar 23 '16 at 12:41
0

Read text from EditText:

EditText et = (EditText) findViewById(R.id.edit_text);
String text = et.getText().toString();

Pass it using Intent:

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("textLabel", text);
startActivity(intent);

Read it in NewActivity:

public class NewActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    String string = intent.getStringExtra("textLabel");

 }
}
Rohit Arya
  • 6,751
  • 1
  • 26
  • 40