2

I have this xml code

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

and java code

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

I want to do a autocompletefragment the invisible at the beginning and when i click on the button to become visible. How can i do this? Sorry for my English. Thank you!

  • set visibility check https://stackoverflow.com/questions/7348150/android-why-setvisibilityview-gone-or-setvisibilityview-invisible-do-not – Pavan Jun 13 '17 at 10:06
  • PlaceAutocompleteFragment don't have method setVisibility – Ігор Бабій Jun 13 '17 at 10:10
  • change the question title you want to handle visibility of fragment then check this may be help https://stackoverflow.com/questions/14347588/show-hide-fragment-in-android – Pavan Jun 13 '17 at 10:12
  • Thak you! I do this)))) – Ігор Бабій Jun 13 '17 at 10:23
  • 1
    Possible duplicate of [Android: why setVisibility(View.GONE); or setVisibility(View.INVISIBLE); do not work](https://stackoverflow.com/questions/7348150/android-why-setvisibilityview-gone-or-setvisibilityview-invisible-do-not) – clemens Oct 10 '17 at 05:05

2 Answers2

6
autocompleteFragment.getView().setVisibility(View.GONE);
clemens
  • 16,716
  • 11
  • 50
  • 65
Ban Daculan
  • 71
  • 1
  • 3
0

Place the PlaceAutocompleteFragment within a RelativeLayout or LinearLayout and use its properties to set visibility as required.

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

Use this code to hide the layout:

RelativeLayout rlSearchPlace = (RelativeLayout) findViewById(R.id.rlSearchPlacement);
rlSearchPlace.setVisibility (View.GONE);
clemens
  • 16,716
  • 11
  • 50
  • 65
Ahamed Mujeeb
  • 615
  • 1
  • 8
  • 13