2010-10-22 71 views
5

我打電話定製對話框正是如此自定義對話框返回數據

 CustomDialog dialog = new CustomDialog(this); 
     dialog.setCancelable(true); 
     dialog.show(); 

現在,如果我有一大堆的對話框中的按鈕,我怎麼回時,我辭退()對話的用戶的選擇?

回答

2

您可以參考以下鏈接 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(); 
0

首先,讓你的對話框中所有按鈕通過方法findViewById()然後將 View.OnClickListener添加到按鈕中,在

View.OnClickListener::onClick() 
{ 
    //Do something 
    dismiss(); 
    //Do something. 
} 

您可以在關閉對話框之前或之後執行某些操作。

+0

你的答案如何提供幫助? – Chaiavi 2012-06-28 10:25:31