how to move data's from one page to the other

2019-09-19 06:09发布

Hi in my app i have placed two edit boxes and on OK button. In the edit boxes i am getting the values such as the first name and second name.

Now i want to do the following process 1. When i click the button OK i move over to the new page, here i want to display the data's entered in the edit boxes of the first page.

2.In the title bar of the second page i want display the data entered in the first edit box ie the first name entered there must be the title of the second page.

how to do this pls help me

2条回答
走好不送
2楼-- · 2019-09-19 06:27

Answer-1)

For that you need to pass the value in intent and that value you get in another activity.

Intent i = new Intent(YourCurrentActivity.this,YourCallingActivity.this);
i.putExtra("key", YourValueToPassAnotherActivity);
startActivity(i);

Now you can get this value in your calling activity using bundle.

Bundle b = getIntent().getExtras();
b.getString("key");

Answer-2)

For that you need to create custom title bar. This might help you

http://oo-androidnews.blogspot.com/2010/03/android-how-to-add-custom-title-bar.html

查看更多
冷血范
3楼-- · 2019-09-19 06:34

Set the OK Button to have an OnClickListener

public void onCreate(Bundle savedInstanceState) {
View okButton = findViewById(R.id.okButtonImg); //assume you are using custom img for OK
okButton.setOnClickListener(okButtonListener);
}

In the Click Listener invoke an Intent. In the Intent you can pass information using "putExtra"

        private OnClickListener okButtonListener = new OnClickListener() {

            public void onClick(View v) {
            Intent secondPageIntent = new Intent(getBaseContext(), SecondPage.class);
            secondPageIntent.putExtra("PASSVALUE","ANY  STRING HERE");
            startActivity(secondPageIntent);

            }
     };

In the second page use getExtras("PASSVALUE") to retrieve data that you passed

See this post for more details http://mylifewithandroid.blogspot.com/2007/12/playing-with-intents.html

查看更多
登录 后发表回答