android - “E/ViewRootImpl:sendUserActionEvent() mView 返回”,而我尝试在自动完成搜索栏中输入(Google Places API)
问题描述
我正在设计一个非常简单的应用程序,其中有一个编辑文本并单击它将打开一个 Google Places API 自动完成搜索栏。我已经生成了 API 密钥并将账单信息添加到我的帐户中。我仍然遇到此错误E/ViewRootImpl: sendUserActionEvent() mView returned
并且自动完成搜索栏崩溃。有人可以指导我。一些代码片段->
Kotlin 代码 ->
class MainActivity : AppCompatActivity() {
companion object{
private const val PLACE_AUTOCOMPLETE_REQUEST_CODE =3
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if(!Places.isInitialized()){
Places.initialize(this,resources.getString(R.string.map))
}
et_location.setOnClickListener {
// These are the list of fields which we required is passed
val fields = listOf(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS)
// Start the autocomplete intent with a unique request code.
val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields).build(this)
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(resultCode== Activity.RESULT_OK){
if(requestCode== PLACE_AUTOCOMPLETE_REQUEST_CODE){
val place : Place = Autocomplete.getPlaceFromIntent(data!!)
et_location.setText(place.address)
}
}
}
}
XML 代码 ->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_location"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="location"
android:inputType="text"
android:focusable="false"
android:focusableInTouchMode="false"
android:textColor="@color/black"
android:textColorHint="@color/black"
android:textSize="18dp" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
一些清单代码->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
.
.
.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/map" />
解决方案
推荐阅读
- python - 为什么sklearn.svm.SVC.predict()的结果与sklearn.svm.SVC.predict_proba()的结果不一致?
- android - 无法使用窗口管理器屏幕更新 android 中的日间和夜间模式
- reactjs - 为什么 useSelector 不包含任何数据?
- javascript - 表单选择/HTML-选择-反应预填充/自动填充/自动填充不起作用
- css - 进度圈完成
- javascript - 如何从包含许多数组的对象中删除数组
- json - 如何在spark2.4之前从字符串的数组json中提取结构
- pwd - 'pwd' 未被识别为内部或外部命令,
- javascript - 如何在函数中使用 classNames 库进行反应?
- java - 通过 Spring Boot / Spring Security UserDetailsService 的身份验证在成功身份验证后导致 302