为我们的项目启用数据绑定并读取一些类似我的问题的错误但我无法解决问题后,我在布局上使用了CustomEditText
作为简单库,但出现了以下错误:
Cause: couldn't make a guess for xx.xxxxx.xxxxxxxx.Core.Libraries.libizo.CustomEditText
图书馆页面link
然后我不确定使用此库是否存在问题,或者布局有错误
我的布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data class="xx.xxxxx.xxxxxxxx">
<variable
name="viewModel"
type="xx.xxxxx.xxxxxxxx.Views.login.viewModel.LoginViewModel" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_10">
...
<libizo.CustomEditText
android:id="@+id/instagram_page_name"
style="@style/Base.TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="left|center"
android:inputType="text"
android:maxLength="50"
android:maxLines="1"
android:minHeight="35dp"
android:singleLine="true"
android:text="javane_milioner"
android:textColor="@color/grey_40"
app:addTextChangedListener="@{viewModel.getUserAccountPageName}"
app:layout_constraintTop_toBottomOf="@+id/textView24"
app:libIZO_clearIconTint="@color/grey_500"
app:libIZO_setBorderColor="#d4d2d3"
app:libIZO_setBorderView="true"
app:libIZO_setClearIconVisible="true"
app:libIZO_setCornerRadius="4dp"
app:libIZO_setPrefixTextColor="@color/colorAccent" />
</RelativeLayout>
</layout>
我测试了添加class属性,但收到以下警告:
Unknown attribute class more... (Ctrl+F1)
应用程序ViewModel类:
public class LoginViewModel extends ViewModel {
private InstagramAccount instagramAccount;
private LoginResultCallback loginResultCallback;
public LoginViewModel(LoginResultCallback callback) {
instagramAccount = new InstagramAccount();
loginResultCallback = callback;
}
public TextWatcher getUserAccountPageName() {
return new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
instagramAccount.setUserPage(s.toString());
}
};
}
public TextWatcher getUserPagePassword() {
return new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
instagramAccount.setUserPassword(s.toString());
}
};
}
public void onLoginClicked(View view) {
if (instagramAccount.isValidate()) {
loginResultCallback.onSuccess();
} else {
loginResultCallback.onError();
}
}
}
我的应用build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'realm-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "xx.xxxxx.xxxxxxxx"
minSdkVersion 19
versionCode 1
versionName "1"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
}
dataBinding {
enabled = true
}
packagingOptions {
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
/* IMPORTANT :
* Be careful when update dependencies, different version library may caused error */
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
...
}
repositories {
mavenCentral()
}
configurations {
cleanedAnnotations
compile.exclude group: 'org.jetbrains', module: 'annotations'
}
答案 0 :(得分:0)
Cause: couldn't make a guess for xx.xxxxx.xxxxxxxx.Core.Libraries.libizo.CustomEditText
删除class="xx.xxxxx.xxxxxxxx"
。
应该是:
<data>
<variable
name="viewModel"
type="xx.xxxxx.xxxxxxxx.Views.login.viewModel.LoginViewModel" />
</data>
顺便说一句:这不是在使用 DataBinding 时在 ViewModel 中使用textWatcher的好方法,您应该使用 {{3} } 代替