Search code examples
javaandroidandroid-edittextpage-title

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


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


Solution

  • 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