我想为平板电脑和手机制作单独的布局,所以我制作了一个片段,在活动中的手机模式下运行良好,在平板电脑布局上我想在对话框中显示片段,但没有任何显示.. .. 当显示拨号时,我得到了标题和我在设计中添加的调试TextView,但片段中没有任何内容......
在课堂上
theVar
我已经覆盖
public class EditPersonDialogFrag extends DialogFragment
我也尝试将片段添加到
中@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_edit_personalia, null);
builder.setTitle(R.string.show_exam).setView(view);
EditPersonaliaFrag personEditFrag = (EditPersonaliaFrag) getChildFragmentManager().findFragmentByTag(EDITFRAG);
if(personEditFrag == null)
{
personEditFrag = new EditPersonaliaFrag();
getChildFragmentManager().beginTransaction().add(R.id.edit_content, personEditFrag, EDITFRAG).commit();
((TextView)view.findViewById(R.id.fragplaceholder)).setText("frag created");
}
else ((TextView)view.findViewById(R.id.fragplaceholder)).setText("frag retrieved");
if(actPerson == null) actPerson = new IdentityCard();
personEditFrag.setPerson(actPerson);
personEditFrag.setCallback(this);
return builder.create();
}
没有更好的结果...... 我也尝试在xml中静态添加片段,但是一旦我为片段添加了一个android:id,应用程序就会因为重复的id而崩溃...(可能视图被多次膨胀?),这使得它无法实现检索片段以设置其数据......
任何帮助表示赞赏!
BTW用于对话框的布局:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
EditPersonaliaFrag personEditFrag = (EditPersonaliaFrag) getChildFragmentManager().findFragmentByTag(EDITFRAG);
if(personEditFrag == null)
{
Log.d(TAG, "recreateing an edit pers frag");
personEditFrag = new EditPersonaliaFrag();
getChildFragmentManager().beginTransaction().add(R.id.edit_content, personEditFrag, EDITFRAG).commit();
((TextView) view.findViewById(R.id.fragplaceholder)).setText("frag created again");
} else
{
Log.d(TAG, "found the edit pers frag");
((TextView) view.findViewById(R.id.fragplaceholder)).setText("frag retrieved again");
}
if(actPerson == null) actPerson = new IdentityCard();
personEditFrag.setPerson(actPerson);
personEditFrag.setCallback(this);
}
答案 0 :(得分:0)
首先,您要实施DialogFragment
,因此我建议您将属性minHeight="1000dp"
和minWidth="1000dp"
添加到LinearLayout
。
然后代替onCreateDialog
做:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.your_dialog_layout, container);
/**Set data to your fragment views**/
return rootView;
}