想想自己学学基础的android知识,做了个简单的石头剪刀布的小程序,点击了总是得不到结果,网上搜索对比别人的代码,发现是变量设置有问题,但是想不通为什么,请各位指点,谢谢
下面是部分代码,全部代码我放在后面吧,怕影响阅读
- class ButtonOnClickListener implements OnClickListener {
- //int choice1 = rga.getCheckedRadioButtonId(); 设置在这里时得不到结果
- //int choice2 = rgb.getCheckedRadioButtonId();
- @Override
-
- public void onClick(View v) {
- int choice1 = rga.getCheckedRadioButtonId(); //设置在这里时运行正常
- int choice2 = rgb.getCheckedRadioButtonId();
-
- if (choice1 != -1 && choice2 != -1) {
- if (choice1 == astone.getId() && choice2 == bknife.getId()
- || choice1 == aknife.getId() && choice2 == bcloth.getId()
- || choice1 == acloth.getId() && choice2 == bstone.getId()) {
- MyToast.show(v.getContext(), "A win!");
- } else if (choice1 == astone.getId() && choice2 == bcloth.getId()
- || choice1 == acloth.getId() && choice2 == bknife.getId()
- || choice1 == aknife.getId() && choice2 == bstone.getId()) {
- MyToast.show(v.getContext(), "B win!");
- } else {
- MyToast.show(v.getContext(), "Draw");
- }
- }
- }
- }
复制代码
|