我已經解決了issue.I只是實現對話框B.Checks一個界面,在對話框中onCreate方法託管對話框是否是活動/對話初始化界面。
下面是代碼
對話框DialogTwo爲A:從對話框乙
public class DialogTwo extends DialogFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
if(!(getActivity() instanceof SelectedItemListener)) {
callback = (SelectedItemListener) getTargetFragment();
}
} catch (Exception e) {
throw new ClassCastException("Calling Fragment must implement SelectedItemListener");
}
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
builder.setTitle(R.string.select_color)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (getActivity() instanceof SelectedItemListener) {
((NewExerciseActivity) getActivity()).manageSelectedItem();
}else {
callback.manageSelectedItem();
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
}
電話:
private void showDialog() {
FragmentActivity activity = (FragmentActivity) getActivity();
FragmentManager fm = activity.getSupportFragmentManager();
DialogTwo dialogTwo = new DialogTwo();
dialogTwo.setTargetFragment(this,0);
dialogTwo.show(fm, "dialogTwo");
}
@Override
public void manageSelectedItem() {
//do something
}
再次什麼是問題?你是否試圖將數據從'DialogFragment' B傳遞給'DialogFragment' A?你找到的解決方案,它有什麼問題? –