【发布时间】:2019-11-01 07:52:53
【问题描述】:
我在我的 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" />
现在,在我活动的 kotlin 方面,我正在这样做:
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() {说未解析的引用:setListener和类没有构造函数
我正在使用 kotlin,而库可能在 Java 中。
可能是什么问题?
【问题讨论】:
-
尝试从 OnOtpCompletionListener() 中删除 ()
-
好的,没关系。未解决的参考:setListener 呢?
-
如果你已经删除了,那么现在有什么问题?
-
错误:该类没有 cnostructor GONE,但错误:未解决存在..
标签: android kotlin one-time-password