2013-01-15 40 views
0

我在Android的Multichoice對話框中遇到了一個小問題。無法將值添加到多選對話框中的Android

我已經完成了以下代碼,用於顯示一個多選對話框並在按鈕單擊事件中調用該對話框。 我已經設置了標題,消息,按鈕,並將對象添加到對話框中。

我可以看到我設置的標題,消息和按鈕,但我無法看到正在添加的項目。爲此,我搜索了幾乎所有的搜索代碼。所有的方法都沒有幫助我。

這裏是我的代碼...

final String[] Values={"Red","Green","Blue"}; 
final boolean[] selCrayons={true,false,true}; 
AlertDialog.Builder dialog=new AlertDialog.Builder(this); 
dialog.setTitle("Crayons List"); 
dialog.setMessage("Select your favouriate Crayon"); 
dialog.setMultiChoiceItems(Values,selCrayons,new DialogInterface.OnMultiChoiceClickListener() { 
    @Override 
    public void onClick(DialogInterface arg0, int arg1, boolean arg2) { 
     // TODO Auto-generated method stub 
     if(arg2) { 
      Toast.makeText(getApplicationContext(), "Selected Color is " + Values[arg1],Toast.LENGTH_LONG).show(); 
     } 
    } 
}); 
dialog.setPositiveButton("SAVE",new DialogInterface.OnClickListener() { 
    @Override 
    public void onClick(DialogInterface dialog, int which) { 
    // TODO Auto-generated method stub 
    } 
}); 
AlertDialog alertDialog=dialog.create(); 
    alertDialog.show(); 
} 

回答

2

setMessagesetMultiChoiceItems會不一起工作。刪除setMessage,您將能夠看到多選項目列表。

如果需要一起使用消息和多選列表,則可以使用自己的自定義視圖作爲對話框。

如何設置自定義視圖,可以參考AlertDialog.Builder setView (View view)方法。

+0

非常感謝CCMinds ...它解決了我的問題。 –

1

我已經遇到此之前,刪除dialog.setMessage(),不幸的是你不能兼得的消息,多選擇

+0

謝謝......它解決了我的pblm先生Boof ... –

相關問題