Search code examples
androidandroid-layoutandroid-dialogfragment

DialogFragment missing content, only showing "ok" button


I'm trying to display a dialogfragment from within a viewpager fragment. For some reason. The only thing that is showing up is the positive ok Button. Can someone help me out here?

Inside of my fragment. I'm calling.

DialogFragment cardDetails = CardDetails_Fragment.newInstance(cardItem);
cardDetails.show(getActivity().getSupportFragmentManager(), "card_details");

Here's my onCreateDialog method.

 @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
    mContext = getActivity(); 
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.fragment_card_details, null);
    TextView cardAttempts = (TextView) view.findViewById(R.id.card_attempts);
    cardAttempts.setText(Integer.toString(_card.attempts));

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

          }
        });
    builder.setCancelable(false); 
     return builder.create();
}

This is what I get.

Dialog Fragment displayed incorrectly


Solution

  • You simply forgot to call setView():

    builder.setView(view);