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

时间:2016-02-26 11:43:33

标签: android google-places-api google-widget

我得到并获取当前位置和所选位置但是当我按下取消交叉按钮时它将清除所有,但现在无法从变量中清除..请帮帮我 Thanx提前

2 个答案:

答案 0 :(得分:0)

您无法设置其可见性。 而且也没有听众 可能会在谷歌下次更新时提供。

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

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

并在其上放置一个clicklistener,以便交叉不可点击

答案 1 :(得分:0)

这个解决方案对我有用:

<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上放置了透明视图。此视图应包含取消按钮。然后,在Activity / Fragment中,在获取视图引用之后:

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

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

相关问题