0

I have created an extension function for listening to click listener for buttons, when I try to access it from Java code it does not work,

Cannot access clicks() from java file, this is what I tried

Can you please suggest how to resolve this.

Thanks R

File - Extension.kt

   fun Button.clicks(): Flow<Unit> = callbackFlow {
        setOnClickListener {
            offer(Unit)
        }
        awaitClose { setOnClickListener(null) }
    }

In my java code - FillingFragment.java

 @NotNull
    @Override
    public Flow<Void> getStartFillingObservableFlow() {
        return dataViewHolder.btnStartFilling.clicks(); //CLICKS IS NOT. RECOGNISED
    }

DataViewHolder.Java

  @BindView(R.id.start_filling_action)
    public Button btnStartFilling;

1 Answer 1

1

Extension functions usually compiles to statics functions so you can invoke them like this:

ExtensionKt.clicks(dataViewHolder.btnStartFilling);
Sign up to request clarification or add additional context in comments.

5 Comments

Hello @andei, I tried that and able to access it now
It gives me an error Required type: Flow <Void> Provided: Flow <Unit>
how can I make the extension function return void?
or should I be working with Unit instead of void
I think your getStartFillingObservableFlow function should return Flow<Unit>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.