我試圖在Android Databinding
中使用Long
值,但無法使其正常工作。這是我試過的一切在Android數據綁定中使用Long值
1:這工作正常。在我開始測試棒棒糖前,我開始遇到崩潰。我不得不從XML
Java
@SerializedName("capacity")
@Expose
Long capacity
/**
*
* @return
* The capacity
*/
@Bindable
public Long getCapacity() {
return capacity;
}
/**
*
* @param capacity
* The capacity
*/
public void setCapacity(Long capacity) {
setAtomicCapacity(capacity);
Log.e(TAG+"Capacity", "" + capacity);
notifyPropertyChanged(BR.capacity);
}
public void setAtomicCapacity(Long basic) {
this.capacity = basic;
}
public TextWatcher onCapacityChange = new SimpleTextWatcher() {
@Override
public void onTextChanged(String newValue) {
Log.e(TAG+"Capacity", newValue);
setAtomicCapacity(Long.valueOf(newValue));
}
};
XML
<EditText
android:id="@+id/outletStockCapacity"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginBottom="16dp"
android:inputType="number"
android:text='@{outlet.capacity != null ? String.valueOf(outlet.capacity) : ""}'
android:addTextChangedListener="@{outlet.onCapacityChange}"
android:singleLine="true"
android:imeOptions="actionNext"/>
2刪除此android:addTextChangedListener="@{outlet.onCapacityChange}"
:利用改變這一切android:addTextChangedListener="@{outlet.onCapacityChange}"
到android:text="@={String.valueOf(outlet.capacity)}"
後=
Equal Operator
因爲雙向綁定默認現在提供。
Java
@SerializedName("capacity")
@Expose
Long capacity = 0L;
/**
*
* @return
* The capacity
*/
@Bindable
public Long getCapacity() {
return capacity;
}
/**
*
* @param capacity
* The capacity
*/
public void setCapacity(Long capacity) {
setAtomicCapacity(capacity);
Log.e(TAG+"Capacity", "" + capacity);
notifyPropertyChanged(BR.capacity);
}
public void setAtomicCapacity(Long basic) {
this.capacity = basic;
}
XML
<EditText
android:id="@+id/outletStockCapacity"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginBottom="16dp"
android:inputType="number"
android:text="@={String.valueOf(outlet.capacity)}"
android:singleLine="true"
android:imeOptions="actionNext"/>
第一次是在Post Lollipop
工作正常,但,不工作Pre-Lollipop
。這是我的SimpleTextWatcher
public abstract class SimpleTextWatcher implements TextWatcher {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void afterTextChanged(Editable s) {
onTextChanged(s.toString());
}
public abstract void onTextChanged(String newValue);
}
我的項目不會因此建立。我不知道爲什麼?我檢查了空,初始化它和所有。但是,它不會只是構建因爲如此