私は、私のrecyclerviewの中にチェックボックス、edittexts、および他の入力を持っています。私は正常にデータバインディングwhickを実装したデータは、Webサービスから取得したデータからデータが取り込まれることを意味します。入力フォースの変更例の値104を107に変更し、スクロールダウンして(EditTextが)ビューポートで長くなり、スクロールバックすると再び値104が返されます。 RecyclerViewは古い値をキャッシュしていて、そのデータバインディングライブラリはモデルを更新していないようです(はい、私はBindable属性と他の必要なものを使用しています)。また、アダプタ内でexecutePendingBindingsメソッドを使用します。recyclerview内のアンドロイドデータバインド
これは私のRecyclerViewアダプタである:これは私のモデルである
< ?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="com.adriagate.adriagateonlineandroid.models.Attribut"/>
<variable
name="attribute"
type="com.adriagate.adriagateonlineandroid.models.Attribut" />
<import type="android.view.View"/>
<variable name="handlers"
type="com.adriagate.adriagateonlineandroid.MyHandlers"/>
</data>
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{attribute.Question}"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@{attribute.Answer}"
android:inputType="number"
bind:visibility="@{attribute.isNumber ? View.VISIBLE : View.GONE}"
/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@{attribute.Answer}"
android:inputType="text"
bind:visibility="@{attribute.isString ? View.VISIBLE : View.GONE}"
/>
<android.support.v7.widget.AppCompatSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
bind:adriagateentries="@{attribute.Choices}"
bind:visibility="@{attribute.isSelect ? View.VISIBLE : View.GONE}"
bind:selectedId="@{attribute.ChoiceId}"
style="@style/Widget.AppCompat.Spinner.Underlined"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
bind:checked="@{attribute.Selected}"
bind:visibility="@{attribute.isBool ? View.VISIBLE : View.GONE}"/>
</LinearLayout>
</layout>
:あなたが有効にすることができますAndroidのメーカー2.1、と
public class Attribute extends BaseObservable {
@Bindable
public String getAnswer() {
return Answer;
}
public void setAnswer(String answer) {
Answer = answer;
notifyPropertyChanged(BR.answer);
}
public List<Choice> getChoices() {
return Choices;
}
public void setChoices(List<Choice> choices) {
Choices = choices;
}
public int getType() {
return Type;
}
public void setTypeype(int attributeType) {
Type = attributeType;
}
@Bindable
public String getChoiceId() {
return ChoiceId;
}
public void setChoiceId(String choiceId) {
ChoiceId = choiceId;
notifyPropertyChanged(BR.choiceId);
}
@Bindable
private String Answer; //tipovi 1
@Bindable
private String ChoiceId; //tipovi 1
private List<Choice> Choices; //za tip 3
private int Type;
public boolean isNumber() {
return this.isNumber = this.getType()==1;
}
private boolean isNumber ;
public boolean isSelect() {
return this.isSelect = this.getType()==3;
}
private boolean isSelect ;
public boolean isString() {
return this.isString = this.getType()==2;
}
private boolean isString ;
private boolean isBool ;
public boolean isBool() {
return this.isBool = this.getType()==5;
}
private boolean isChecked;
public boolean isChecked() {
return this.Answer =="D";
}
}
エディットテキストに変更を取り、あなたのデータモデルにそれらを適用するコードですか? –
ユーザーはappを使用し、EditText内で値を変更します。双方向データバインディングライブラリはモデルを更新します。それはそのように動作するはずです。 anglejsのようなWeb世界での2方向データ結合ライブラリは、どのように動作し、これはデータバインディングがどのように機能するかということです。 –
1)編集テキストに変更を加えてモデルに残すコードは表示されません。私はあなたのためにそれを行うつもりの魔法の接着剤を記述するAndroidのデータバインディングのページに何も表示されません。 2)データモデルが変更されたときに通知機能を呼び出すことはありません。 –