我正在尝试添加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数据库,如果该代码正确,我就不会这样做,因为我尚未测试过
我有同样的问题。确保您启用了适用于Android的Google Places API,而不仅仅是启用了开发者控制台中的Places API 。“ Android的Places API”将不会显示在API和Auth / API下,因为它尚未流行。您将必须使用API搜索框进行搜索。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句