2013-01-17 95 views
7

我在創建對話框時遇到了問題。它確實出現,但其內部空白,只顯示一個空白框。Android DialogFragment爲空

Dialog類:

public class SomeDialog extends DialogFragment{ 

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    builder.setView(inflater.inflate(R.layout.somelayout, null)); 

    return super.onCreateDialog(savedInstanceState); 
} 
} 

一個活動,創建對象和調用顯示方法:

SomeDialog obj = new SomeDialog(); 
obj.show(getFragmentManager(), "randomtag"); 

回答

6
return super.onCreateDialog(savedInstanceState); 

您正在返回父類的方法。你應該歸還你自己的。更改爲:

return builder.create(); 
0

在我的情況下,問題是在

public static DialogFragment newInstance(int param) { 
    Bundle args = new Bundle(); 
    args.putInt(EXTRA_PARAM, param); 

    DialogFragment fragment = new DialogFragment(); // Here is an error. 
    fragment.setArguments(args); 
    return fragment; 
} 

的錯行應與

DialogFragment fragment = new YourDialogFragment(); 
// Or YourDialogFragment fragment = new YourDialogFragment(); 
被替換