i want to make separate layouts for tablet and phone, so i made a fragment, which works well in phone mode inside an activity, on tablet layout i would like to display the fragment in a Dialog, but nothing shows up.... when displaying the dialoge, i get the title and a debug TextView i added in the design, but nothing from the fragment...
In class
public class EditPersonDialogFrag extends DialogFragment
i have overriden
@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();
}
i also tried to put the fragment adding into
@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);
}
with no better result... i also tried to add the fragment statically in the xml, but as soon as i addded an android:id for the fragment, the app crashed due to duplicated id... (maybe the view is inflated several times?), making it impossible to retrieve the fragment to set its data...
any help appreciated!
BTW the layout used for the dialog:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/edit_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--fragment
android:id="@+id/edit_frag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.nohkumado.aikiexamen.EditPersonaliaFrag"
/-->
<TextView
android:id="@+id/fragplaceholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PlaceHolder" />
</LinearLayout>