本文介绍了为什么OnclickListener不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button)findViewById(R.id.button1);
btn1.setOnClickListener(buttonSendOnClickListener);
}
Button.OnClickListener buttonSendOnClickListener
= new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
switch (arg0.getId()) { //execution does not go here when I click button
case R.id.button1:
setContentView(R.layout.main2);
//do your button 1 work here
break;
case R.id.cancel:
setContentView(R.layout.main);
//do your button 1 work here
break;
}
}
};//on click;
}
请帮忙。
Please, help.
推荐答案
这篇关于为什么OnclickListener不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!