将AutoCompleteTextView中的Observable更改为EditText
我正在尝试使用Kotlin和RxJava编辑一些预先存在的代码,以便为用户提供更好的UI布局。
初始ui使用AutoCompleteTextEdit将用户的Google Places结果显示为用户类型。 我试图改变它,所以用户键入,结果显示在输入字段下的ListView而不是附加到输入字段。
我的问题是,我只能得到数据显示在列表视图中,如果我离开当前的代码,以便它也显示在AutoCompleteTextView由于代码是为observable和自定义RxFilterableArrayAdapter编写的方式。
有了这个代码,搜索工作,但显示在下拉菜单,以及列表视图。 (见下文)
private fun setupView(view:View) { val tripPlanningResult = view.findViewById(R.id.trip_planning_api_results) as ListView val starting_location = view.findViewById(R.id.trip_planning_starting_location) as AutoCompleteTextView val destination_address = view.findViewById(R.id.trip_planning_destination_address) as AutoCompleteTextView val plan_route_button = view.findViewById(R.id.trip_planning_plan_route_button) val tripPlanningService = TripPlanningService.sharedTripPlanningService(context) val cityBounds0 = CityCache.getInstance(context, "cities", true) .getCityRegion(cityId!!) //Creates an Observable to watch for text input from the AutoCompleteTextView val filterFeeder = object : RxFilterableArrayAdapter.RxFilterFeeder<TripPlanningService.ProposedLocation> { val inputs = PublishSubject<String>() override fun output(): Observable<List<TripPlanningService.ProposedLocation>> { return Observable.combineLatest(listOf(inputs, cityBounds0), { it }) .flatMap { val text = it[0] as String val cityBounds = it[1] as LatLngBounds tripPlanningService.proposeLocationsForUserInput(cityBounds, text) } } override fun input(filterText: String) { Timber.w("Got input text $filterText") inputs.onNext(filterText) } } val autoCompleteAdapter = RxFilterableArrayAdapter(context, android.R.layout.simple_list_item_1, filterFeeder) tripPlanningResult.setAdapter(autoCompleteAdapter) starting_location.setAdapter(autoCompleteAdapter) destination_address.setAdapter(autoCompleteAdapter) setAutoCompleteItemListeners(starting_location) setAutoCompleteItemListeners(destination_address) plan_route_button.setOnClickListener { sendRequest() } }
我想将starting_location和destination_address更改为EditText,但仍然使用filterfeeder正确观察它们,并仅在tripPlanningResults中显示结果。 我似乎无法使适配器正确工作。
我怎样才能让EditText订阅像AutoCompleteTextView这样的Observable呢。
- 如何将Android的Java第三方库转换为kotlin?
- 如何检测Android应用程序是否正在用Espresso进行UI测试
- 为什么我的Android应用程序中的第一个计算速度很慢,而所有后续的计算都很快
- RxAndroid / RxLifeCycle – 处理处理onError而不是onComplete
- com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期的BEGIN_ARRAY,但在第1行第2列的路径
- 使用RxJava + Kotlin解析数据时出错
- Androidunit testing没有被嘲笑
- “对象”不是这个域的模式的一部分
- 在模块之间共享编译依赖关系