Kotlin 中的 OTP 输入 - 库 android-otpview-pinview

OTP Input in Kotlin - library android-otpview-pinview

我在 Android 应用程序中使用以下库来为 OTP 提供 UI:

https://github.com/mukeshsolanki/android-otpview-pinview

成功,添加如下依赖:

implementation 'com.github.mukeshsolanki:android-otpview-pinview:2.1.0'

此外,添加了以下行:

maven { url "https://jitpack.io" }

在如下布局中使用它:

       <com.mukesh.OtpView
        android:id="@+id/otp_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:inputType="number"
        android:itemBackground="@drawable/drawable_otp_entry"
        android:textColor="@android:color/white"
        app:itemCount="4"
        app:lineColor="@color/colorPrimary"
        app:viewType="none" />

现在,在我的 activity 中的科特林方面,我正在这样做:

class MainActivity : AppCompatActivity() {
var otpView: OtpView? =null
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    otpView = findViewById(R.id.otp_view)
    otpView.setListener(object:OnOtpCompletionListener() {
        override fun onOtpCompleted(otp:String) {
            // do Stuff
            Log.d("onOtpCompleted=>", otp)
        }
    })
    }
}

错误在行:otpView.setListener(object:OnOtpCompletionListener() {未解决的引用:setListenerThe class 没有构造函数

我正在使用 kotlin,库可能在 Java。

可能是什么问题?

我想 SetListener 不再受支持,请尝试使用

 otpView = findViewById(R.id.otp_view)
    otpView!!.setOtpCompletionListener(object :OnOtpCompletionListener
    {
        override fun onOtpCompleted(otp: String?) {

        }

    })