15

我有几个关于DialogFragment使用 Robolectric 测试课程的问题,因为我在 Internet 上遇到了关于这个主题的完全缺乏信息。

  1. 传递给的正确论点是onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)什么?
  2. 我无法将参数传递给DialogFragment,我正在使用以下方法:

    activity = new Activity();
    dialog = new DialogFragment();
    Bundle bundle = new Bundle();
    dialog.setArguments(bundle);
    FragmentManager fm = activity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(dialog, "fragment");
    ft.commit();
    

每当代码尝试访问参数时,它都会以NullPointerException.

将高度赞赏有关这些主题的任何想法。

4

1 回答 1

0

你用DialogFragment错了。您不应该提交片段,而是调用show.DialogFragment

activity = new Activity();
dialog = new DialogFragment();
Bundle bundle = new Bundle();
dialog.setArguments(bundle);
FragmentManager fm = activity.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
dialog.show(ft, "fragment");
于 2013-11-15T05:58:40.757 回答