Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change placeholder text in an autocomplete activity of android google place?

I am using Option 2: Use an intent to launch the autocomplete activity

Is it possible to change the "search" place holder text to something such as "enter your city". I found a solution but for javascript, suppose support android as well.

It seems it could be done with a PlaceAutocompleteFragment, but I am using my own EditText to launch autocomplete by using an intent, so it is not helpful.

enter image description here

like image 521
thanhbinh84 Avatar asked Jul 28 '17 06:07

thanhbinh84


2 Answers

No there is no way and if you want than you have to create your own. But as u use the EditText(mention in Comment Section) so may be this technique is useful for your.

Code:

PlaceAutocompleteFragment autocompleteFragment;
autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    autocompleteFragment.setOnPlaceSelectedListener(this);
    autocompleteFragment.setHint("Search New Location");

XMl :

<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/left_drawable_padding"
android:layout_marginTop="@dimen/margin_five"
android:layout_marginLeft="@dimen/margin_five"
android:layout_marginRight="@dimen/margin_five"
android:background="@drawable/search_background"
android:orientation="vertical">
    <fragment
        android:id="@+id/place_autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
        />

and as i used android:background="@drawable/search_background" so u have to create your own background shape(acc. to your need).

first picture : enter image description here

Second picture : enter image description here

thrid picture : enter image description here

Fourth picture : enter image description here

like image 183
Dhruv Tyagi Avatar answered Sep 30 '22 11:09

Dhruv Tyagi


Unfortunately, there is no way to change the hint text with the autocomplete intent. You need to make your own widget, like the PlaceAutocompleteFragment.

like image 38
One Code Man Avatar answered Sep 30 '22 11:09

One Code Man