getSupportFragmentManager

getSupportFragmentManager

所以我在片段中创建对话框时出错

这是代码:

     public Dialog onCreateDialog(Bundle savedInstanceState) {
        int title = getArguments().getInt("title");

        return new AlertDialog.Builder(getActivity())
                .setIcon(R.drawable.logo)
                .setTitle(R.string.groupDetails_rename)
                .setPositiveButton(R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                                ((GroupDetailsFragment)  getSupportFragmentManager())
                                        .doPositiveClick();
                            }
                        }).create();
    }


我在((GroupDetailsFragment) getSupportFragmentManager())而不是getSupportFragmentManager()上写什么错误?

最佳答案

GroupDetailsFragment f = (GroupDetailsFragment) getSupportFragmentManager().findFragmentByTag("tag");

f.doPositiveClick();


当您调用“ show()”时,“ tag”将被传递

getSupportFragmentManager-> v4
getFragmentManager-> nativ

关于android - 在 fragment 中创建警报对话框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18251966/

10-11 19:23