How to start new activity on button click

后端 未结 24 2258
傲寒
傲寒 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:41

    When user clicks on the button, directly inside the XML like that:

    Using the attribute android:onClick we declare the method name that has to be present on the parent activity. So I have to create this method inside our activity like that:

    public void buttonClickFunction(View v)
    {
                Intent intent = new Intent(getApplicationContext(), Your_Next_Activity.class);
                startActivity(intent);
    }
    

提交回复
热议问题