How to start new activity on button click

后端 未结 24 1603
傲寒
傲寒 2020-11-21 05:54

In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?

24条回答
  •  [愿得一人]
    2020-11-21 06:51

    Place button widget in xml like below

    After that initialise and handle on click listener in Activity like below ..

    In Activity On Create method :

    Button button =(Button) findViewById(R.id.button); 
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           Intent intent = new 
                Intent(CurrentActivity.this,DesiredActivity.class);
                startActivity(intent);
        }
    });
    

提交回复
热议问题