简体   繁体   中英

Using kotlin extension function in Java code

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;

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

ExtensionKt.clicks(dataViewHolder.btnStartFilling);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM