Getting constant false value from method

前端 未结 3 506
迷失自我
迷失自我 2021-01-21 17:42

I have 3 questions

 private static int NUMBER_OF_QUESTIONS = 3;
static boolean[] answer = new boolean[NUMBER_OF_QUESTIONS];
static boolean[] checked = new boolea         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 18:01

    Where are you updating isAnswered array. In the code snippet you have provided, it updates only answer and checked arrays.

    Probably that is why you are always getting false for all 3 array elements of isAnswered array.

    Where are you updating isAnswered array. In the code snippet you have provided, it updates only answer and checked arrays.

    Probably that is why you are always getting false for all 3 array elements of isAnswered array.

    Hi Roman,

    I believe you have multiple radio groups each with 3 radio buttons. If that is the case, just slight modification in you above code snippet should work for you.

    rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.radioButton1) {
                Toast.makeText(getActivity(), "True", Toast.LENGTH_SHORT).show();
                checked[0] = true;
                answer[0] = true;
            } else {
                checked[0] = true;
                answer[0] = false;
            }
            // update isAnswered[0] to true. as this gets invoked when you choose any radio button.
            isAnswered[0] = true;
        }
    });
    

    Please let me know if this helps.

提交回复
热议问题