Android studio学习小白,这是老师布置的作业,使用CheckBox组件设计界面,下面是我的相关设计,不足之处,希望各位大佬指正
在design中,拖拽两个CheckBox,我设计的是Login和register和一个choice按钮。下面贴上相关的代码;
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mApple = findViewById(R.id.apple);mPear = findViewById(R.id.pear);final TextView textView = findViewById(R.id.textView);Button button1 = findViewById(R.id.button2);button1.setOnClickListener((View v) -> {mCount++;textView.setText(getCheckBoxText());});}private String getCheckBoxText(){String text = "进入APP!";if (mApple.isChecked()) {text += "登录成功 欢迎!";/* if (mPear.isChecked())text += "and pear.";elsetext +=".";*/}else if (mPear.isChecked()) {text += "没有账号要先注册噢";}elsetext += "nothing.";return text;
}
运行程序,最后出现的结果是;
注意:在写程序时,不要像我一样忘记加相关的包噢