Parth Bhoiwala
Parth Bhoiwala

Reputation: 1322

android - add button to auto complete search box

I have implemented Google's PlaceAutocompleteFragment in my android app and it looks like this below. enter image description here

But I want to add a button in the end just how google maps has a microphone.

enter image description here

Below is my code so far:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    >
    <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"
        />
</android.support.v7.widget.CardView>

Place select Code:

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            String placeName = place.getName().toString();
            LatLng latLng = place.getLatLng();
            mMap.addMarker(new MarkerOptions().position(latLng).title(placeName));
            mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));

        }
        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            Log.i(TAG, "An error occurred: " + status);
        }
    });

A sample code would be nice. Thank you so much :)

Upvotes: 0

Views: 2358

Answers (1)

Dasser Basyouni
Dasser Basyouni

Reputation: 3252

Very sorry about being so late to reply, but I have reinstalled and downloaded the whole Android Studio and the SDK because of some errors

Here is my suggestions to you :-

  1. To use 3rd library FloatingSearchView
  2. To customize you self but that will take some time respectively to the 3rd library and here are the easy tutorials that will helps you Custom Google Place Autocomplete Android and How to customize PlaceAutocomplete widget dialog design to list places Question

  3. Is to try enter deeper in Google's code to customize it knowing that this will be made by extending Google's class and copying the whole code of Google's then editing it is a Regenerated class

    Also the last step I have reached deeper it the code was to know that this method is the method which creates the Google search

    private void zzzG() {
    int var1 = -1;
    try {
        Intent var2 = (new PlaceAutocomplete.IntentBuilder(2)).setBoundsBias(this.zzaRk).setFilter(this.zzaRl).zzeq(this.editSearch.getText().toString()).zzig(1).build(this.getActivity());
        this.startActivityForResult(var2, 1);
    } catch (GooglePlayServicesRepairableException var3) {
        var1 = var3.getConnectionStatusCode();
        Log.e("Places", "Could not open autocomplete activity", var3);
    } catch (GooglePlayServicesNotAvailableException var4) {
        var1 = var4.errorCode;
        Log.e("Places", "Could not open autocomplete activity", var4);
    }
    if (var1 != -1) {
        GoogleApiAvailability var5 = GoogleApiAvailability.getInstance();
        var5.showErrorDialogFragment(this.getActivity(), var1, 2);
    }}
    

    Also, give me a feedback if you have a problem of any of those solutions

Upvotes: 1

Related Questions