Как изменить поведение пользовательского интерфейса фрагмента автозаполнения Google на раскрывающийся список? - PullRequest
0 голосов
/ 15 февраля 2020

Я хотел, чтобы фрагмент автозаполнения в Google google отображался как раскрывающийся список в моем приложении. Онлайн после прочтения документации кажется, что она может быть запущена как намерение или фрагмент.

Я решил использовать API автозаполнения мест Google в качестве внедренного фрагмента, но всякий раз, когда я нажимаю на свой фрагмент в моем приложении, он открывает другую панель поиска, которая перекрывает мой текущий пользовательский интерфейс, делая мой дизайн не связным.

Проблема, с которой я сталкиваюсь при нажатии

Где мой фрагмент находится в моем пользовательском интерфейсе

 private void showAlertDialogUpdateAddress(){

    AlertDialog.Builder alertDialog=new AlertDialog.Builder(ProfileActivity.this);
    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
            getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentById(R.id.update_place_autocomplete_fragment)).commit();
        }
    });

    //alertDialog.setTitle(addressType);
    alertDialog.setMessage("Add an Address:");

    LayoutInflater inflater=this.getLayoutInflater();
    order_address=inflater.inflate(R.layout.update_address,null);

    // final MaterialEditText edtAddress=(MaterialEditText) order_address.findViewById(R.id.edtAddress);
    AutocompleteSupportFragment edtAddress=  (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.update_place_autocomplete_fragment);
    edtAddress.getView().findViewById(R.id.places_autocomplete_search_button).setVisibility(View.GONE);
    ((EditText) edtAddress.getView().findViewById(R.id.places_autocomplete_search_input)).setHint("Enter your new address");
    ((EditText) edtAddress.getView().findViewById(R.id.places_autocomplete_search_input)).setTextSize(14);
    edtAddress.setPlaceFields(Arrays.asList(Place.Field.ID,Place.Field.NAME, Place.Field.ADDRESS,Place.Field.LAT_LNG));

    edtAddress.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(@NonNull com.google.android.libraries.places.api.model.Place place) {
            shipAddress=place;
            // Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
        }

        @Override
        public void onError(@NonNull Status status) {

        }
    });

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:orientation="vertical"
        >
        
        <fragment
            android:id="@+id/update_place_autocomplete_fragment"
            android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <RadioGroup
            android:id="@+id/address_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="24dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/update_place_autocomplete_fragment">

            <RadioButton
                android:id="@+id/addAddressHomeRadioButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Home" />

            <RadioButton
                android:id="@+id/addAddressWorkRadioButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Work" />

            <RadioButton
                android:id="@+id/addAddressOtherRadioButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Other" />
        </RadioGroup>


    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

Вышеприведенное соответствует разделу моего кода, где я реализовал фрагмент xml. Любая помощь будет с благодарностью.

...