5
我打电话定制对话框正是如此自定义对话框返回数据
CustomDialog dialog = new CustomDialog(this);
dialog.setCancelable(true);
dialog.show();
现在,如果我有一大堆的对话框中的按钮,我怎么回时,我辞退()对话的用户的选择?
我打电话定制对话框正是如此自定义对话框返回数据
CustomDialog dialog = new CustomDialog(this);
dialog.setCancelable(true);
dialog.show();
现在,如果我有一大堆的对话框中的按钮,我怎么回时,我辞退()对话的用户的选择?
您可以参考以下链接 http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
例子:
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
您还可以使用警告对话框定制
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) Context.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();
首先,让你的对话框中所有按钮通过方法findViewById()
然后将 View.OnClickListener
添加到按钮中,在
View.OnClickListener::onClick()
{
//Do something
dismiss();
//Do something.
}
您可以在关闭对话框之前或之后执行某些操作。
你的答案如何提供帮助? – Chaiavi 2012-06-28 10:25:31