放置自动完成片段清除按钮设置可见性消失



我获取并获取当前位置和选定位置,但是当我按下取消十字按钮时,它将清除所有内容,但现在无法从变量中清除。 请帮助我提前感谢

这个解决方案对我有用:

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

我已经在 PlaceAutocompleteFragment 上放置了一个透明的视图。此视图应涵盖取消按钮。然后,在活动/片段中,在查看视图引用后:

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

此解决方案有效,因为当您输入空字符串时,我们会获得相同的结果。

您无法将其可见性设置为消失。而且也没有听众。
也许它将在谷歌下一次更新中可用。

不是一个正确的解决方案,但如果你真的需要它。您可以使用相对布局在十字按钮上创建白色视图,以便用户无法看到十字按钮。

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

并在上面放置一个点击监听器,以便十字不可点击

最新更新