【问题标题】:Place Autocomplete fragment clear button set visibility gone放置自动完成片段清除按钮设置可见性消失
【发布时间】:2016-06-09 14:46:55
【问题描述】:

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

【问题讨论】:

  • autoCompleteTextView.setText("");就这么简单
  • 无法从变量中清除??
  • 如何在自动完成片段中检查空文本??当我单击交叉(取消)按钮时,它会清除但无法从变量中清除当前位置。我想删除十字按钮。请帮助我@Bajirao Shinde
  • @Shaalz 你有没有找到一个解决方案来检查 autocompleteText 是否为空?

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


【解决方案1】:

这个解决方案对我有用:

<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;
        }
    });

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

【讨论】:

    【解决方案2】:

    你不能设置它的可见性消失。 而且也没有听众。
    可能它会在 google 下一次更新中可用。

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

     <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 以使 cross 不可点击

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 2017-07-22
      • 2017-11-15
      • 2015-12-20
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多