Android Button Onclick

后端 未结 9 2034
猫巷女王i
猫巷女王i 2020-11-29 03:41

OK I\'m new to android dev\'s and Java, so I\'m having problems with on click method here\'s my code. I know I\'ve gotta be close, thanks in advance. All I want my button to

9条回答
  •  醉梦人生
    2020-11-29 04:37

    this will sort it for you

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Button but1=(Button)findViewById(R.id.button1);
    
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
                Intent int1= new Intent(MainActivity.this,xxactivity.class);
                startActivity(int1);
            }
        });
    }
    

    You just need to amend the xxactivity to the name of your second activity

提交回复
热议问题