我正在尝试在Dialog或DialogFragment中嵌入Fragment
public class addAccountDialog extends DialogFragment
{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.add_account_dialog, container);
accountType.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
passwordFragment newFragment = new passwordFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_base, newFragment);
transaction.commit();
}
}
}
}
<LinearLayout
android:id="@+id/fragment_base"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="3" >
</LinearLayout>
我尝试使用Dialog和DialogFragment都没有用。有没有人能够在对话框中实现片段。
提前谢谢你。
罗杰
答案 0 :(得分:1)
您无法将Fragments
置于其他Fragments
内。
我的建议是将您的Fragments
置于Activity
范围内,然后通过XML执行Activity
Dialog
主题:
<activity android:theme="@android:style/Theme.Dialog" />
编辑:只是一个注释,从API-17(4.2)开始,您现在可以嵌套片段:Nested Fragments