How do I get a button to open another activity?

前端 未结 8 1016
执笔经年
执笔经年 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:57

    Button T=(Button)findViewById(R.id.button_timer);
    T.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i=new Intent(getApplicationContext(),YOURACTIVITY.class);
            startActivity(i);
        }
    });
    

提交回复
热议问题