Я пытаюсь добавить функцию автозаполнения Google Place, она работала отлично, но каждый раз, когда я нажимаю на нее, чтобы найти свое местоположение, моя клавиатура показывает, а затем немедленно исчезает
код xml
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Java-код
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
location = place.getName().toString();
FirebaseUser current_user = FirebaseAuth.getInstance().getCurrentUser();
String user_id = current_user.getUid();
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(user_id);
HashMap<String, String> userMap = new HashMap<>();
userMap.put("User location", location);
mDatabase.setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Intent addlocation = new Intent(selectlocation.this, home.class);
addlocation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(addlocation);
finish();
}
}
});
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
}
});
а также я не проверял его, но помогите мне проверить код Java, если он использовался правильно. Я пытаюсь отправить местоположение пользователя в мою базу данных firbase, я не уверен, что этот код правильный, потому что я еще не проверял его