Android 在对话框或FragmentDialog中嵌入片段
我试图在对话或对话片段中嵌入一个片段Android 在对话框或FragmentDialog中嵌入片段,android,dialog,fragment,Android,Dialog,Fragment,我试图在对话或对话片段中嵌入一个片段 public class addAccountDialog extends DialogFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = inflate
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>
public类addAccountDialog扩展了DialogFragment
{
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态)
{
super.onCreate(savedInstanceState);
视图=充气机。充气(R.layout.add\u account\u对话框,容器);
accountType.setOnItemSelectedListener(新的OnItemSelectedListener()
{
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id)
{
passwordFragment newFragment=新的passwordFragment();
FragmentTransaction=getFragmentManager().beginTransaction();
事务.replace(R.id.fragment\u base,newFragment);
commit();
}
}
}
}
我试过在对话框和DialogFragments中使用它,但都没有用。有人能够在对话框中实现片段吗
先谢谢你
罗杰您无法将
片段
放入其他片段
中
我的建议是将您的片段
像平常一样放在活动
中,然后在XML中这样做,给活动
一个对话框
主题:
<activity android:theme="@android:style/Theme.Dialog" />
您为什么需要这样做?我认为这是不可能的,因为片段管理器来自活动类。如果我们知道您想要完成什么,我们可能会提供其他建议。您可以嵌套片段,但这是不可取的:[[1]:感谢Atlos及时的回复和代码,我将尝试Theme.Dialog,看看它是如何工作的,如果它提供了我想要的体验。