1

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>
Noh Kumado
  • 1,551
  • 2
  • 9
  • 15

1 Answers1

0

First of all, you're implementing a DialogFragment so I would recommend you to add attributes minHeight="1000dp" and minWidth="1000dp" to your LinearLayout.

Then instead of onCreateDialog do :

@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;
}
Balraj
  • 328
  • 2
  • 7
  • Nope, unfortunately no change, the fragment doesn't show :( – Noh Kumado Apr 07 '18 at 11:45
  • can you try without using `view.invalidate()` , cause I don't think you need to call that explicitly. Also a little offtopic advice, why don't you use **Master Detail** layout for tablets?. Also, can you show where you're making fragment transaction? ( in code ). – Balraj Apr 07 '18 at 20:08
  • removed the invalidate, didn't change anzthing, i added it in the first place because nothing showed :( so at he moment the only solution that works, is to declare an activity and give it the stly Dialog :( – Noh Kumado Apr 19 '18 at 16:59