我遇到了一个问题,因为我想对 numberPicker 进行数据绑定。但是我在任何地方都找不到任何示例,并且像往常一样,它在第一次尝试时不起作用……在十几个之后也不起作用:)。
所以我想质疑你的知识。
所以这基本上是我在我的 Xml 中所做的:
(我的代码的开头)
<data>
<variable
name="profilmvvm"
type="com.example.dupla.sparktennis.viewmodels.ProfilViewModel"/>
<import type="com.example.dupla.sparktennis.Services.ConversiontoInt"/>
</data>
在同一个文件中有点沮丧:
<NumberPicker
android:layout_width="50.0dp"
android:layout_height="100.0dp"
android:id="@+id/numberPickerNiveauProfil"
android:gravity="center_horizontal"
android:layout_marginLeft="10.0dp"
android:layout_marginTop="40.3dp"
android:layout_marginRight="10.0dp"
android:layout_marginBottom="10.0dp"
android:value="@{profilmvvm.niveau.niveau}"/>
这是我在 Fragment 活动中数据绑定它的方式:
profilViewModel = new ProfilViewModel(getContext(), calendrier, rencontre, niveau, userLog, personne);
mBinding.setProfilmvvm(profilViewModel);
这是 ViewModel :
public ProfilViewModel(Context context, CalendrierDisponibilite cal, TypeDeRencontre renc, Niveau niv, Userslogs user, Personne pers) {
this.context = context;
this.calendrier = cal;
this.niveau = niv;
this.user = user;
this.personne = pers;
this.rencontre = renc;
}
@Bindable
public CalendrierDisponibilite getCalendrier() {
return calendrier;
}
public void setCalendrier(CalendrierDisponibilite calendrier) {
this.calendrier = calendrier;
notifyPropertyChanged(BR.calendrier);
}
@Bindable
public TypeDeRencontre getRencontre() {
return rencontre;
}
public void setRencontre(TypeDeRencontre rencontre) {
this.rencontre = rencontre;
notifyPropertyChanged(BR.rencontre);
}
@Bindable
public Personne getPersonne() {
return personne;
}
public void setPersonne(Personne personne) {
this.personne = personne;
notifyPropertyChanged(BR.personne);
}
@Bindable
public Niveau getNiveau() {
return niveau;
}
public void setNiveau(Niveau niveau) {
this.niveau = niveau;
notifyPropertyChanged(BR.niveau);
}
@Bindable
public Userslogs getUser() {
return user;
}
public void setUser(Userslogs user) {
this.user = user;
notifyPropertyChanged(BR.user);
}
我是 100% 我的视图模型中有数据。我只是不确定为什么它适用于所有其他正常工作的小部件(我有很多 EditText 和 CheckBox)。
那么有什么我做的不对吗?是否可以 DataBind 一个 NumberPicker ?
谢谢你的分享:)