colorpicker, can't set listener

Viewed 212

I'm quite new to Java. I'm programming an app to cooperate with Arduino through UDP protocol.
I would like to use this colorpicker https://github.com/QuadFlask/colorpicker but I'm unable to interact with it

I tried using setOnColorSelectedListener with the following code

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ColorPickerView colorpicker = findViewById(R.id.colorpick);
    colorpicker.setOnColorSelectedListener(new OnColorSelectedListener() {
        @Override
        public void onColorSelected(int selectedColor) {

        }
    });
}

But it gives me this error:

Cannot resolve method 'setOnColorSelectedListener(anonymous com.flask.colorpicker.OnColorSelectedListener)'

Does anyone have some experience with this library?
Please let me know if you know how to solve it.

2 Answers

The method: setOnColorSelectedListener does not exists.

Just read the source code, there are many samples:

ColorPickerView colorPickerView = (ColorPickerView) findViewById(R.id.color_picker_view);

        colorPickerView.addOnColorChangedListener(new OnColorChangedListener() {

            @Override public void onColorChanged(int selectedColor) {

                // Handle on color change

                Log.d("ColorPicker", "onColorChanged: 0x" + Integer.toHexString(selectedColor));

            }

        });

        colorPickerView.addOnColorSelectedListener(new OnColorSelectedListener() {

            @Override

        public void onColorSelected(int selectedColor) {

            Toast.makeText(

                    SampleActivity2.this,

                    "selectedColor: " + Integer.toHexString(selectedColor).toUpperCase(),

                    Toast.LENGTH_SHORT).show();

        }

    });

You have a typo.

setOnColorSelectedListener should be addOnColorSelectedListener; there can be multiple listeners, so we are adding to the list of listeners rather than replacing the one true listener.

Related