我正在学习kotlin和android架构组件.我在谷歌地图上有一个简单的地图切换按钮用例.
我想使用数据绑定将地图切换按钮标签绑定到我的ViewModel中的MutableLiveData字段.
我在Activity中的onCreate方法中设置MapViewModel中的mapType val.如果我理解正确,这应该触发mapLabel val由于使用Transformations.map而改变.
它不起作用......为什么?
这是我的版本:
MapViewModel.kt
class MapViewModel : ViewModel() {
val mapType: MutableLiveData<MapType> = MutableLiveData()
val mapLabel: LiveData<String> = Transformations.map(mapType, {
if (it == MapType.MAP) "SAT" else "MAP"
})
}
enum class MapType {
SAT, MAP
}
Run Code Online (Sandbox Code Playgroud)
activity_maps.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="vm"
type="uk.co.oliverdelange.wcr_android_kt.ui.map.MapViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
<Button
android:id="@+id/map_toggle"
style="@style/Wcr_MapToggle"
android:layout_marginTop="110dp"
android:layout_marginEnd="12dp" …Run Code Online (Sandbox Code Playgroud) android kotlin android-livedata android-viewmodel android-architecture-components
我有一个简单的文本字段,当用户在文本字段中提交值时,它会执行某些操作:
TextField(
textInputAction: TextInputAction.search,
onSubmitted: onSearchEmail,
)
Run Code Online (Sandbox Code Playgroud)
足够简单......我正在尝试编写一个集成测试,检查用户提交文本字段时执行的操作 - 但是我无法弄清楚如何模拟用户按下键盘上的“搜索”按钮( android) 或 iOS 中的任何等效项...
我天真地尝试过driver.enterText("a@b.c\r\n");,但没有成功。
我的集成测试:
test('entering email performs a search', () async {
driver.tap(find.byValueKey('search-email-search-box'));
driver.enterText("a@b.c\r\n"); // <- doesn't work
await driver.waitFor(find.text("some text));
});
Run Code Online (Sandbox Code Playgroud)
我真的不希望用户必须按下屏幕上的按钮,键盘按钮工作正常。
编辑:只是为了澄清 - 文本被输入到该字段中,以便该位起作用,只是提交不起作用。