0
BattleFragment battleFragment;
battleFragment = BattleFragment.newInstance("0");
FragmentManager fm = getActivity().getSupportFragmentManager();
fm.beginTransaction()
.replace(R.id.fragmentContainer, battleFragment)
.commit();
上面的代码是我用来创建一个新的片段并显示它。但是,当我在片段中并尝试获取活动时,它将返回null。当我运行isAttached()时,它返回false。有什么我忘记了吗?Android活动不附加到片段
'然而,当我在片段,并得到活动返回null。“究竟是什么意思?向我们展示实际不起作用的代码。 – Falmarri 2014-12-11 03:49:24
'fragmentContainer'应该是'FrameLayout'。请检查 – Rohit 2014-12-11 03:54:00