Place Autocomplete fragment clear button set visibility gone

3k views Asked by At

I get and fetch current location and selected location but when i pressed cancel cross button it will clear it all, but now cannot clear from variable.. please help me Thanx in advance

2

There are 2 answers

0
Aakash Jindal On

You can not set its visibility gone. and there is no listener also.
May be it will be available in google next update.

Not a correct solution but if you really need it. You can create a white view on cross button using relative layout so the user is not able to see the cross button.

 <RelativeLayout
        android:layout_below="@+id/actionBar"
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_40sdp"
        android:alpha=".9"
    android:background="@drawable/home_page_search"
   android:layout_margin="10dp"

    >

<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"
 />


        <View
            android:id="@+id/view1"
            android:layout_width="@dimen/_50sdp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:background="@color/white"
            android:layout_margin="@dimen/_5sdp"
            />


    </RelativeLayout>

and put a clicklistener on it so that cross is not clickable

0
Alejandro Traver On

This solution has worked for me:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <fragment android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
            android:id="@+id/place_autocomplete_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <View
            android:id="@+id/view_callback"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_gravity="right|center_vertical"
            android:background="@android:color/transparent"/>
    </FrameLayout>

I have put a transparent view over the PlaceAutocompleteFragment. This view should cover the cancel button. Then, in Activity/Fragment, after obtining view reference:

closeCallback.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            autocompleteFragment.setText("");
            return true;
        }
    });

This solution works because when you put a empty string we obtain the same result.