数据绑定validation器错误,由Ilhasoft + Kotlin

我试图用Kotlin使用Android库“Ilhasoft数据绑定validation器” ,但我得到这个错误:未解决的参考:validation。

这是我的根build.gradle:

buildscript { ext.kotlin_version = '1.1.60' ext.android_plugin_version = '3.0.0' ext.data_binding_validator_verson = '1.0.0' repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { jcenter() maven { url 'https://jitpack.io' } } } task clean(type: Delete) { delete rootProject.buildDir } 

这是我的APP build.gradle:

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' android { compileSdkVersion 27 buildToolsVersion "27.0.0" defaultConfig { applicationId "com.main.janderson.meuapp" minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } dataBinding { enabled = true } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" kapt "com.android.databinding:compiler:$android_plugin_version" compile "com.github.Ilhasoft:data-binding-validator:$data_binding_validator_verson" } repositories { mavenCentral() google() } kapt { generateStubs = true } 

那是我的片段_cadastrar_user:

                            

并完成这是我的片段中的onCreateView:

 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment_cadastrar_user, null) //Binding Api val binding: FragmentCadastrarUserBinding = DataBindingUtil.setContentView(activity as Activity, R.layout.fragment_cadastrar_user) val validator = Validator(binding); binding.validate.setOnClickListener(View.OnClickListener { if (validator.validate()) { registerUser() } }) binding.setUser(user); view.user_phone.addTextChangedListener(PhoneNumberFormattingTextWatcher()) return view } 

并补充这是一个与我的错误的图片。

有人能帮助我吗? 谢谢!

One Solution collect form web for “数据绑定validation器错误,由Ilhasoft + Kotlin”

validate是库示例中按钮的ID。

你应该使用你想要validation的按钮的ID。 我认为这是new_user_button

所以绑定,它应该像newUserButton

所以你的完整例子就像

 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment_cadastrar_user, null) //Binding Api val binding: FragmentCadastrarUserBinding = DataBindingUtil.setContentView(activity as Activity, R.layout.fragment_cadastrar_user) val validator = Validator(binding); // CHANGE IN BELOW LINE binding.newUserButton.setOnClickListener(View.OnClickListener { if (validator.validate()) { registerUser() } }) binding.setUser(user); view.user_phone.addTextChangedListener(PhoneNumberFormattingTextWatcher()) return view } 
Kotlin language will be the best programming language for Android.