Android 在复选框被选中后,我如何获得它们的标签?

Android 在复选框被选中后,我如何获得它们的标签?,android,android-studio,checkbox,Android,Android Studio,Checkbox,我试过这个: private int[] intCheckBox = { R.id.monCheck, R.id.tueCheck, R.id.wedCheck }; private CheckBox[] realCheckBox = new CheckBox[intCheckBox.length]; private int i; 然后: 但是,当我运行应用程序时,在我选中其中一个框后显示了一个错误,错误是: E/AndroidRuntime

我试过这个:

private int[] intCheckBox = {
        R.id.monCheck,
        R.id.tueCheck,
        R.id.wedCheck
};

private CheckBox[] realCheckBox = new CheckBox[intCheckBox.length];

private int i;
然后:

但是,当我运行应用程序时,在我选中其中一个框后显示了一个错误,错误是:

E/AndroidRuntime: FATAL EXCEPTION: main
              java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
我知道有另一种方法可以通过逐个设置来获取标签甚至字符串。。。然而,我想使用数组来显示标记,以便进行进一步的编码,以获得int值“whatIReallyWantToGet”:


我在网上搜索了很长时间。但是没有用。我只是一个新的学习者,从课本和网上资源。请帮助或尝试给出一些如何实现这一点的想法。非常感谢你

根据您共享的代码,我觉得您没有重置变量i的值

这可以解释为什么异常表示您正在尝试访问数组的索引3

E/AndroidRuntime:致命异常:主 java.lang.ArrayIndexOutOfBoundsException:length=3;指数=3

private CompoundButton.OnCheckedChangeListener showFinal = new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        String outPut2 = "";

        if (realCheckBox[i].isChecked()){
            outPut2 += realCheckBox[i].getTag();
            outPutText3.setText(outPut2);

        }
E/AndroidRuntime: FATAL EXCEPTION: main
              java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
 java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.set(Calendar.MONTH, position);
        cal.set(Calendar.DAY_OF_WEEK, whatIReallyWantToGet);
        cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
        int month = cal.get(Calendar.MONTH);
        String output = "";
        while (cal.get(Calendar.MONTH) == month) {
            output += cal.get(Calendar.DAY_OF_MONTH) + "/" + (cal.get(Calendar.MONTH) + 1) + ",";
            cal.add(Calendar.DAY_OF_MONTH, 7);
        }