2010-10-22 22 views
5

tôi gọi một hộp thoại tùy chỉnh thuslyReturn dữ liệu từ Tuỳ chỉnh Dialog

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

Bây giờ, nếu tôi có một loạt các nút trong hộp thoại, làm thế nào để trở lại sự lựa chọn của người dùng khi tôi bỏ() hộp thoại ?

Trả lời

2

Bạn có thể tham khảo link này http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Ví dụ:

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); 

Bạn cũng có thể sử dụng hộp thoại cảnh báo cho tùy chỉnh

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

Đầu tiên, có được tất cả các nút trong hộp thoại của bạn thông qua phương pháp findViewById() sau đó thêm View.OnClickListener vào nút, trong

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

Bạn có thể làm điều gì đó trước hoặc sau khi loại bỏ hộp thoại.

+0

Câu trả lời của bạn giúp ích như thế nào? – Chaiavi