2013-03-21 31 views
0

我打開對話框,以便我的用戶可以從列表中選擇一年。Android的DialogFragment數組中的字符串打開數組?

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
builder.setTitle("Choose Year") 
     .setItems(years, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       // The 'which' argument contains the index position 
       // of the selected item 

      } 
     }); 
return builder.create(); 

years變量是String[],但它可能是多達100個條目。有沒有辦法讓對話框打開,在可見的初始範圍內顯示列表中的特定項目?例如,如果從1913年到2013年的年數一直在1913年開放,那麼是否有必要在1980年的時候將其列入中間名?

回答

0

嘗試使用DialogFragment的onCreateView方法中的ListView充氣佈局。