How do I get a button to open another activity?

前端 未结 8 1028
执笔经年
执笔经年 2020-12-02 13:09

I\'ve added a button to my activity XML file and I can\'t get it to open my other activity. Can some please tell me step by step on how to do this?

8条回答
  •  甜味超标
    2020-12-02 13:55

    Apply the following steps:

    1. insert new layout xml in folder layout
    2. rename window2
    3. add new button and add this line: android:onClick="window2"

    mainactivity.java

    public void openWindow2(View v) {
            //call window2
            setContentView(R.layout.window2);           
        }
    }
    

提交回复
热议问题