我正在尝试为我的 android 应用检查单选按钮的数量。我的应用程序中有 15 个单选按钮,我只是想计算其中的前 8 个。“test”是 EditText 组件,我试图在其中显示所选单选按钮的数量。FinalSubmit是已实现侦听器的按钮。下面是单选按钮的代码,以及我在以下代码中使用的代码onClickListener:public class Main2Activity extends AppCompatActivity { RadioButton rb1, rb2, rb3, rb4, rb5, rb6, rb7, rb8, rb9, rb10, rb11, rb12, rb13, rb14, rb15; int rbChecked = 0; Button finalsubmit; EditText test; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); finalsubmit = (Button)findViewById(R.id.button3); test = (EditText)findViewById(R.id.editText); rb1 = (RadioButton)findViewById(R.id.radioButton1); rb2 = (RadioButton)findViewById(R.id.radioButton2); rb3 = (RadioButton)findViewById(R.id.radioButton3); rb4 = (RadioButton)findViewById(R.id.radioButton4); rb5 = (RadioButton)findViewById(R.id.radioButton5); rb6 = (RadioButton)findViewById(R.id.radioButton6); rb7 = (RadioButton)findViewById(R.id.radioButton7); rb8 = (RadioButton)findViewById(R.id.radioButton8); rb9 = (RadioButton)findViewById(R.id.radioButton9); rb10 = (RadioButton)findViewById(R.id.radioButton10); rb11 = (RadioButton)findViewById(R.id.radioButton11); rb12 = (RadioButton)findViewById(R.id.radioButton12); rb13 = (RadioButton)findViewById(R.id.radioButton13); rb14 = (RadioButton)findViewById(R.id.radioButton14); rb15 = (RadioButton)findViewById(R.id.radioButton15); } });}现在的问题是,只要我点击提交按钮,要么应用程序崩溃,要么被重定向到我的应用程序的第一个活动。请有人帮助我,我已经完成了谷歌并通过了 StackOverflow,但我被卡住了。
1 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
对不起,伙计们,我犯了一个错误,以下是我所做的更改。现在它工作得很好:
test.setText(String.valueOf(rbChecked));
添加回答
举报
0/150
提交
取消