【发布时间】:2020-06-23 03:14:34
【问题描述】:
我有编辑文本,它将从用户那里获得输入
<EditText
android:inputType="number"
android:id="@+id/etQuantity"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/button_background"
android:backgroundTint="@color/green"
android:hint="Quantity"
android:padding="5dp"
android:onTextChanged="@{inspect::onQuantityTextChanged}"
android:textColor="@color/lightblack" />
<TextView
android:id="@+id/tvCalculatedTotal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/button_background"
android:backgroundTint="@color/green"
android:hint="Total"
android:inputType="number"
android:padding="5dp"
android:text="@={inspect.calculatedTotal}"
android:textColor="@color/lightblack" />
我想在编辑文本中将其设置为文本视图 onTextchanged
class InspectViewModel(repository: UserRepository) : ViewModel() {
var calculatedTotal: String = ""
fun onQuantityTextChanged(
s: CharSequence,
start: Int,
before: Int,
count: Int
) {
calculatedTotal= s.toString()
}
}
我得到了值,但它没有更新文本视图,我使用了实时数据但得到了 ANR
【问题讨论】:
-
你能告诉我如何在xml中实现和
标签吗?
标签: android kotlin mvvm data-binding android-viewmodel