【问题标题】:How to handle visibility of place autocomplete fragment in android如何在android中处理位置自动完成片段的可见性
【发布时间】:2017-11-15 01:03:39
【问题描述】:

我有这个 xml 代码

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

和java代码

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
                getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                // TODO: Get info about the selected place.
                Log.i(TAG, "Place: " + place.getName());
            }

            @Override
            public void onError(Status status) {
                // TODO: Handle the error.
                Log.i(TAG, "An error occurred: " + status);
            }
        });

我想在开始时以及单击按钮以使其可见时对不可见进行自动完成片段。 我怎样才能做到这一点? 对不起我的英语不好。 谢谢!

【问题讨论】:

标签: android


【解决方案1】:
autocompleteFragment.getView().setVisibility(View.GONE);

【讨论】:

    【解决方案2】:

    PlaceAutocompleteFragment 放在RelativeLayoutLinearLayout 中,并根据需要使用其属性设置可见性。

    <RelativeLayout
      android:id="@+id/rlSearchPlacement"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp"
      android:layout_marginRight="5dp"
      android:layout_marginLeft="5dp"
      android:background="@color/bg_white">
    <fragment
        android:id="@+id/placeAutoFragment"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
    </RelativeLayout>
    

    使用此代码隐藏布局:

    RelativeLayout rlSearchPlace = (RelativeLayout) findViewById(R.id.rlSearchPlacement);
    rlSearchPlace.setVisibility (View.GONE);
    

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-07
      相关资源
      最近更新 更多