2

I am using auto complete places widget by Google. I noticed that when I place it in my activity and I click on it then it opens a fragment on top of my activity (with a status bar although my activity is full screen)

How can I embed the whole behavior within my activity so the widget being clicked on to initiate search is actually the same widget populated with suggestions

 <androidx.cardview.widget.CardView

    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:background="@null"
    app:layout_constraintBottom_toBottomOf="@+id/ibLocationAction"
    app:layout_constraintEnd_toStartOf="@+id/ibLocationAction"
    app:layout_constraintStart_toEndOf="@+id/ibClose"
    app:layout_constraintTop_toTopOf="@+id/ibLocationAction">

    <fragment
        android:id="@+id/autocomplete_fragment"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</androidx.cardview.widget.CardView>



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

        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                Log.i(GlobalVar.TAG, "Place: " + place.getName());
                chosenPlace = place;
            }

            @Override
            public void onError(Status status) {
                Log.i(GlobalVar.TAG, "An error occurred: " + status);
            }
        });
Snake
  • 14,228
  • 27
  • 117
  • 250
  • What do you mean by the same widget populated with suggestiona , its not very clear – Tamir Abutbul Jan 27 '19 at 18:45
  • Right now if you click on the search widget that you embed in you activity xml, then it shows another "google search widget" on top of as if it is a new activity. I want to interact with the orginal widget not new overlayed widget – Snake Jan 27 '19 at 20:29
  • Check my answer - hope it can help you – Tamir Abutbul Jan 27 '19 at 20:44

1 Answers1

3

According to the Place Autocomplete documentation here, you can have either Autocomplete widget in overlay mode (this is called "MODE_OVERLAY"), or you can have Autocomplete widget in fullscreen mode (this is called MODE_FULLSCREEN ).

When I first got to know place autocomplete I encountered this problem as well but it seems like you can't achieve interaction with your pressed view and you can only choose between MODE_FULLSCREEN and MODE_OVERLAY as I mentioned above(all according to the documentation)

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • The problem is what you mentioned is option 2 in the document where intent is being used. I am using option 1 which is supposed to be the embedded one! – Snake Jan 27 '19 at 20:49
  • I will try to make it a bit more clear - option 1 or MODE_OVERLAY is basically another search fragment on top of your current layout, option 2 is another search fragment that opens in a new screen. I understand your questions about the intent but instead of writing a really long comment have a look at [this thread here](https://stackoverflow.com/questions/34416817/how-to-implement-placeautocompletefragment-and-placeautocompleteactivity-to-get) , hope this can help you – Tamir Abutbul Jan 27 '19 at 20:56
  • I showed you the code I wrote. Here is the thing, this is not an intent. Option 1 in the website refers to just calling the fragment, no intents ,no modes. You know what I mean? – Snake Jan 27 '19 at 23:22
  • 1
    Ye,and i think that even when you are juat caling a fragment it will open a new fragment on top and you cant realy use your original search view.I can say that this is kind of logical - if google would allow it i think that there could be a problem when you are using a search view at the bottom of your screen , and the user wont have screen space to select an option(hope this was clear) – Tamir Abutbul Jan 28 '19 at 07:18
  • 1
    Yea makes sense. I think they should just get rid of option 1 so others like me are not confused. Thank you – Snake Jan 28 '19 at 15:12
  • just remember that if you will remove option 1 , this can be very annoying to open a new page for every search – Tamir Abutbul Jan 28 '19 at 15:35