我想知道自定义Dialog与自定义AlertDialog相比有什么区别?它们是否在对话框中以按钮,列表,复选框等形式提供免费功能?
其次,我想知道自定义AlertDialog可用的代码片段@ http://developer.android.com/guide/topics/ui/dialogs.html(下面转载的代码)是否完整。我尝试使用它,它在我调用dialog.show()的时候崩溃了:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
虽然创建自定义对话框(有效)的代码更简单:
Dialog dialog = new Dialog(MyActivity.this);
dialog.setContentView(R.layout.dialog_custom);
dialog.setTitle("Shopping List Name");
dialog.setCancelable(true);
dialog.show();
感谢您的耐心等待。
米@光洁度
编辑:我终于开始工作了。我想我现在明白了Dialog和AlertDialog之间的区别。我记录了这个@ http://geekjamboree.wordpress.com/2011/11/19/dialog-vs-alertdialog/