Android Button Onclick

后端 未结 9 2037
猫巷女王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:20

    Method 1:

    public void onClick(View v) {
              Intent i = new Intent(currentActivity.this, SecondActivity.class);
             startActivty(i);
            }
    

    Method 2:

    Button button = (Button) findViewById(R.id.mybutton);
     button.setOnClickListener(new OnClickListener() {
    
        public void onClick(View v) {
             Toast.makeText(this, "Button Clicked", Toast.LENGTH_LONG).show();
    
        }
     });
    

提交回复
热议问题