Android 泛型类的数据绑定
我有一个适用于活动的通用基类的布局。该活动的定义如下:Android 泛型类的数据绑定,android,android-layout,android-databinding,Android,Android Layout,Android Databinding,我有一个适用于活动的通用基类的布局。该活动的定义如下: public abstract class MyActivity<TUserType extends UserType> extends AppCompatActivity 公共抽象类MyActivity扩展了AppCompatActivity 我希望能够对此类使用数据绑定,但当我尝试在布局xml中使用此类中的设置时,编译时无法识别该设置。这是我的布局: <?xml version="1.0" encoding="ut
public abstract class MyActivity<TUserType extends UserType> extends AppCompatActivity
公共抽象类MyActivity扩展了AppCompatActivity
我希望能够对此类使用数据绑定,但当我尝试在布局xml中使用此类中的设置时,编译时无法识别该设置。这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="activity"
type="com.exampl.MyActivity"/>
</data>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
android:layout_alignParentTop="true"
android:visibility="@{activity.progressBarVisibility}"/>
</LinearLayout>
</layout>
“progressBarVisibility”在MyActivity中定义,是公共的。我猜我可能必须定义用户类型,但我不知道如何在xml方面进行定义。或者这还不受支持?无需定义用户类型。 这就是我的情况: 公共抽象类BaseStateVM扩展了BasePVM{
@Bindable
public int getState() {
return state;
}
希望这对你有帮助。
完整的代码是。无需定义用户类型。 这就是我的情况: 公共抽象类BaseStateVM扩展了BasePVM{
@Bindable
public int getState() {
return state;
}
希望这对你有帮助。
完整的代码是