Android的Dialog类设计的太糟糕了!
题目的噱头是大了点。
但是,这是不争的事实。
我们可以看看这么一个需求:我要在一个界面上显示一个对话框。不管是简单的确认对话框,还是可以选择是否的对话框。
Windows下面的代码:
private void button1_Click(object sender, System.EventArgs e) {
if(textBox1.Text == "") {
MessageBox.Show("You must enter a name.", "Name Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else {
// Code to act on the data entered would go here.
}
}
|
参看这里: http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox.aspx
但是,跑到Android下,折腾了半天还没折腾出点东西来。
先来看文档:
android.app android.app.AlertDialogandroid.app.Dialog android.app.AlertDialog A subclass of Dialog that can display one, two or three buttons. If you only want to display a String in this dialog box, use the setMessage() method. If you want to display a more complex view, look up the FrameLayout called "body" and add your view to it: FrameLayout fl = (FrameLayout) findViewById(R.id.body);
fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
|
没看太懂吧。是的,我也没看懂。
为啥呢。这段描述就和怎么用AlertDialog一点关系都没有。
再等看到这一段,得。哥们这次彻底歇菜了。
Protected ConstructorsAlertDialog(Context context) AlertDialog(Context context, int theme) AlertDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) |
也就是说,这个类人家压根都没有准备让你直接构造出来。咋整呢?
兄弟我都懒得说了,用代码来说明吧。
new AlertDialog.Builder(AlertDialogSamples.this) |