3

I got an error by using this code

 holder.box.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean newState = !arrEmps.get(position).isChecked();
            arrEmps.get(position).isChecked() = newState;
            Toast.makeText(mContext.getApplicationContext(),
                    arrEmps.get(position).getName() + "check" + newState,
            Toast.LENGTH_LONG).show();
        }
    });

the error line is

arrEmps.get(position).isChecked() = newState;

the error message is

Error:(86, 48) error: unexpected type
required: variable
found:    value
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kara
  • 123
  • 2
  • 9
  • 2
    `isChecked()` calls a method that returns a value. You can't assign a new value to a method call. Look for a method called `setChecked` instead and use that. – khelwood Apr 20 '18 at 07:58
  • `arrEmps.get(position).isChecked()` is a getter you can not assign a value to it . Add a Setter and use `arrEmps.get(position).setChecked()` – ADM Apr 20 '18 at 07:58

1 Answers1

1

I think you are using a default method from a clickable item, if so read this, if not go on

Referring to the Clickable interface, you can see that there are two methods:

isChecked()

is a getter and it only returns the value of the checked variable, as you can see inspecting(ie: it tells you whether a checkbox is checked or not):

@ViewDebug.ExportedProperty
@Override
public boolean isChecked() {
    return mChecked;
}

There is also a setter,

setChecked(boolean checked)

This setter set the value of the property of the checked state of the clickable interface. (ie: is set a checkbox as checked or not)

If you are not using a default clickable item/view, but you have your own method

If the object you are using is a custom one, create a setter for the property you want to set by adding a setChecked(boolean value) method

public void setChecked(boolean value){
  mValue = value;
}

here you can learn how to create getters and setters quickly

And I always reccomend this tutorial (imo the best) for learning android basics.

Hope this helps

Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66