DialogFragment缺少内容,只显示“ok”按钮

时间:2013-01-04 06:39:29

标签: android android-layout android-dialogfragment

我正在尝试从viewpager片段中显示一个dialogfragment。由于某些原因。唯一出现的是积极的ok按钮。有人可以帮助我吗?

我的片段里面。我在打电话。

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

这是我的onCreateDialog方法。

 @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();
}

这就是我得到的。

Dialog Fragment displayed incorrectly

1 个答案:

答案 0 :(得分:4)

您根本忘记致电setView()

builder.setView(view);