Start another activity by clicking a button

前端 未结 2 558
猫巷女王i
猫巷女王i 2021-02-09 09:25

So heres my problem. I set up a button that when clicked should open a new activity but when it is clicked I receive an error: Unfortunately \"app_name\" has stopped working my

2条回答
  •  名媛妹妹
    2021-02-09 09:54

    You need to call another activity like this inside the OnClickListener() of button

    Button mondayEdit= (Button)findViewById(R.id.button1);
        mondayEdit.setOnClickListener(new OnClickListener() 
        {   public void onClick(View v) 
            {   
                Intent intent = new Intent(main.this, secondActivity.class);
                    startActivity(intent);      
                    finish();
            }
        });
    

提交回复
热议问题