pass values from one screen to another?

后端 未结 3 1902
失恋的感觉
失恋的感觉 2021-01-25 05:16

I need to pass data\'s (String) from one screen to another screen. At the time of button click i need to pass values from first screen to the next screen.

3条回答
  •  忘了有多久
    2021-01-25 05:44

    Register an onClickListener for the button and pass the required data by adding it to the Intent.

    Button button = (Button) findViewById(R.id.button);
     button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                                Intent intent = new Intent(Activity1.this, Activity2.class); 
                                intent.putExtra("extra", data);
                                startActivity(intent); 
                 });  
    

    You can get the data in Activity2 by

    String extra = getIntent().getStringExtra("extra"); 
    

提交回复
热议问题