我正在尝试使用 onClick() 方法从单个类执行多个布局屏幕 这是我的代码
Button bt1,bt2;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = (Button)findViewById(R.id.button);
bt2 = (Button)findViewById(R.id.button1);
onClick(); //onClick(View) in MainActivity cannot be applied to ()
}
public void onClick(View v){
if(v.getId()==R.id.button){
setContentView(R.layout.next1);
}
else if(v.getId()==R.id.button){
setContentView(R.layout.next1);
}
}
请大家帮帮我,谢谢
最佳答案
在这种情况下,您必须使用 fragment 。根据按钮单击加载任一 fragment 。
如果您在这种情况下使用 setContentView
,那么您的代码将变得笨拙,并且跟踪 View 将非常乏味。
关于java - 尝试从单个类执行多个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32497705/