text box error in android

2019-08-16 10:34发布

问题:

hi in my app i have 2 Activity named as A and B.

Now i am placing 2 edit boxes for typing the first name and last name, with an OK button in Activity A.

After entering the data and pressing OK button i want to show the first name and last name as the title text of Activity B.

i have tried and succeed in passing those names to be subject of my mail in the same app.

pls help me...

回答1:

You can use putExtra and getStringExtra with your Intent to pass String parameters to a new Activity.

In Activity A:

Intent intent = new Intent(this, B.class);
intent.putExtra("firstName", firstName);
intent.putExtra("lastName", lastName);
startActivity(intent);

In Activity B:

@Override
protected void onCreate(Bundle savedInstanceState) {
    String firstName = getIntent().getStringExtra("firstName");
    String lastName = getIntent().getStringExtra("lastName");
        ....
}

There are also getFooExtra and putExtra methods for all of the other basic datatypes.