-3

I have a problem with onclicklistener in checkbox.where checkbox does not work

so here my code:

checkBox.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        String position = sebab.isChecked();
                                        getKonsultasiutils getSebab = (com.example.ikhwan.ta.getKonsultasiutils) arrayList.get(position);

                                        Toast.makeText(MenuTransaksi.this, getSebab.getKd_sebab(), Toast.LENGTH_SHORT).show();
                                        getKd_sebab = getSebab.getKd_sebab();


                                    }
                                }

this warning is incompatble type in String position.

i want show data string when button checked.

  • 1
    Possible duplicate of [How to do something when a checkbox change state?](https://stackoverflow.com/questions/11332111/how-to-do-something-when-a-checkbox-change-state) – BakaWaii Aug 13 '17 at 03:24
  • `sebab.isChecked()` is likely to be a `boolean`. You can't assign it to a `String`. – BakaWaii Aug 13 '17 at 03:26

1 Answers1

1

CompoundButton.isChecked() returns a boolean, not a String, so you cannot write String s = checkBox.isChecked(). If you want to assign it to a String, you could instead write String s = String.valueOf(checkBox.isChecked()).

Additionally, in the code you posted, you named your String position, and then pass the value to arrayList.get(). In this context, position should be an int, not a String or a boolean.

Ben P.
  • 52,661
  • 6
  • 95
  • 123