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
Asked
Active
Viewed 2,972 times
1
-
autoCompleteTextView.setText(""); simple as that – Sree Reddy Menon Feb 26 '16 at 11:47
-
cannot clear from variable means ?? – Bajirao Shinde Feb 26 '16 at 12:37
-
how to check empty text in place autocomplete fragment?? when i clicking cross(cancel) button it jzt clear but cannot clear the current location from the variable. i want to remove the cross button. Plz help me @ Bajirao Shinde – Shaalz Feb 27 '16 at 07:45
-
@Shaalz have you found a solutin to check if autocompleteText is empty ? – ghita Mar 22 '16 at 09:13
2 Answers
1
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.

Alejandro Traver
- 79
- 6
0
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

Aakash Jindal
- 104
- 3