add onclick listener to predefined button?

后端 未结 5 698
春和景丽
春和景丽 2020-12-01 09:03

I\'ve got the following button in my xml layout file...

5条回答
  •  被撕碎了的回忆
    2020-12-01 09:33

    You can try this.

    public class myNewClass extends Activity implements OnClickListener {
        ................... 
        ...................       
    
        Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(this);
    
            public void onClick(View v) {
                    Intent i = new Intent();
                    Bundle extras = new Bundle();
    
            // This will catch the button click 
            // Now do what you wanted to do as a 
            // result of the onClick
            }
     }
    

提交回复
热议问题