2012-07-14 75 views

回答

0

用於創建像這樣的警報對話框。在您的按鈕點擊偵聽器中調用此方法。

private void showDialog() { 

final CharSequence[] Countries = { "India", "U.S.A", "U.K" }; 

AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); 
alt_bld.setIcon(R.drawable.icon); 
alt_bld.setTitle("Select Country"); 

//you can set the Default selected value of the list, Here it is 0 means India 
alt_bld.setSingleChoiceItems(Countries, 0, 
new DialogInterface.OnClickListener() { 
public void onClick(DialogInterface dialog, int item) { 

Toast.makeText(getBaseContext(), Countries[item], 
Toast.LENGTH_LONG).show(); 
alert.cancel(); 
} 
}); 

alert = alt_bld.create(); 
alert.show(); 

} 
+0

請告訴我如何實現一個警告對話框中的2個單選按鈕 – 2012-07-14 11:22:20

+0

有三個單選按鈕,上面的代碼,如印度,U.S.A。和U.k.在那之後運行這些你就會明白 – Shalini 2012-07-14 11:23:17