2013-08-16 25 views
0

緊跟這裏顯示的骨架:AlertDialog應該是類型對話框

http://developer.android.com/guide/topics/ui/dialogs.html#

所有在這個頁面上,他們使用的聲明像這樣的:

public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    builder.setTitle(R.string.pick_color); 
     .setItems(R.array.colors_array, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
      // The 'which' argument contains the index position 
      // of the selected item 
     } 
    }); 
    return builder.create(); 
} 

這種方法的數據類型「對話框」,但使用了構建器,因此該方法的返回類型是「AlertDialog」。 Eclipse可以理解地告訴我這些是不兼容的,並且當我嘗試做類似的事情時不會編譯我的代碼。它也不會讓我把builder.create()調用的結果轉換成類型對話框,所以沒有解決方法。我怎樣才能解決這個問題,並讓我的代碼編譯? 謝謝。

回答

相關問題