Щелкните за фрагментом, когда показано DialogFragment - PullRequest
0 голосов
/ 01 июня 2019

Мне нужно иметь доступ для клика по моему фрагменту (например, по нажатию кнопки), когда отображается DialogFragment.

Но когда я нажму за пределами DialogFragment, это будет отклонено.

Используемый код для отображения DialogFragment :

FragmentManager fragmentManager = getFragmentManager();

MyDialogMapFragment dialogFragment = new MyDialogMapFragment();
dialogFragment.show( fragmentManager, "" );

MyDialogMapFragment Класс:

public class MyDialogMapFragment extends DialogFragment {

    private Activity mActivity;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        rootView = inflater.inflate(R.layout.dialog_map_info, container, false);

        return rootView;

    }

    public Dialog onCreateDialog(Bundle savedInstanceState) {

        Dialog dialog = new Dialog(getActivity(), R.style.DialogMap);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_map_info);
        dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;

        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(dialog.getWindow().getAttributes());
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;

        dialog.getWindow().setAttributes(lp);

        return dialog;

    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        if (context instanceof Activity) {
            mActivity = (Activity) context;
        }

    }

}

dialog_map_info.xml Макет:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="90dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp">

    <RelativeLayout
        android:id="@+id/mainFrame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:clickable="true"
        android:focusable="true"
        android:background="@drawable/background_map_info">

        <ProgressBar
            android:id="@+id/progress_loader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_centerInParent="true" 
            style="?android:attr/progressBarStyle" />

        <TextView
            android:id="@+id/itemTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Test" />

    </RelativeLayout>

</FrameLayout>

Ниже изображение опишет, каков мой макет:
Sample of my layout

1 Ответ

0 голосов
/ 01 июня 2019

Если вам нужно обнаружить щелчок во время отображения диалогового окна, было бы легче установить onClickListener для представления в вашем диалоговом окне.

Когда вы вызываете onClickListener, вы можете выполнитьнажмите кнопку button.perfomClick () или, что еще лучше, вызовите функцию, которую вызывает кнопка onClickListener.

...