このダイアログは、Fragment
が含まれており、また、ダイアログ上の断片のための別のDialogFragment
public class MyDialogFragment extends DialogFragment implements
MyFragmentOnTheDialog.MyFragmentOnTheDialogListener,
MyAdditionalPopupDialogFragment.MyAdditionalPopupDialogFragmentListener
{
をポップアップDialogFragment
の骨格例であり、それが動的に追加されます。
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// fragment dynamically added
mFragmentManager = getChildFragmentManager();
// create a new instance of the fragment.
mMyFragmentOnTheDialog= MyFragmentOnTheDialog.newInstance();
// Add the fragment to the layout by replacing a frame on the layout
FragmentTransaction transaction = mFragmentManager.beginTransaction();
transaction.replace(R.id.frame_my_fragment, mMyFragmentOnTheDialog);
transaction.addToBackStack(null);
transaction.commit();
}
ポップアップ追加DialogFragment
MyAdditionalPopupDialogFragmentについては...
btnPick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
MyAdditionalPopupDialogFragment frag = MyAdditionalPopupDialogFragment.newInstance();
// pass to the Dialog Fragment a reference to this container class
// in order to set up the interface between this fragment and that fragment.
// The reference to the MyAdditionalPopupDialogFragment is returned to 'frag'
frag.setMyAdditionalPopupDialogFragmentListener(EventAddFragment.this);
frag.show(ft, frag.TAG);
}
});
(あなたがコールバックを設定するには、あなたの他のDialogFragment
でsetMyAdditionalPopupDialogFragmentListenerを追加する必要があります)
/**
* Sets the listener interface with the container class to allow a callback to be made from this
* fragment. The container class must implement the interface
* @param listener The container class that has implemented the MyAdditionalPopupDialogFragment interface
* @return A reference to this fragment
*/
public MyAdditionalPopupDialogFragment setMyAdditionalPopupDialogFragmentListener(MyAdditionalPopupDialogFragmentListener listener) {
mListener = listener;
return this;
}
再。ヤンジェの答え - context
の問題はありません。
あなたが 'DialogFragment'から' Fragment'を起動していると言うと、 'Fragment'がダイアログの一部であるか、別の' DialogFragment'が表示されていますか? – SimonH
@SimonH、それはダイアログの一部ではなく、別個の断片です。 – user1324887