2014-03-28 157 views
0

我的XML文件(的XMLList)數組列表中創建這樣的:動態列表視圖彈出窗口

private static ArrayList<File> xmlList = new ArrayList<File>(); 
public static ArrayList<File> XMLContact(File directory, File contactDirectory, 
ArrayList<Contact> myContactList) { 
if (!(directory.exists())) { 
directory.mkdirs();} 
if (!(contactDirectory.exists())) { 
contactDirectory.mkdirs(); 
} 
Calendar c = Calendar.getInstance(); 
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy hh-mm-ss"); 
String FileName = df.format(c.getTime()); 
File newxmlfile = new File(Environment.getExternalStorageDirectory()+ "/newfile/contactfile/"+FileName+"xml"); 
xmlList.add(newxmlfile); 

然後要顯示該列表的彈出窗口中的元素(點擊後在一個按鈕:按鈕接觸)。所以我寫了這個代碼

private void onClickButtonContact(View view) { 
Button myButton = (Button) view.findViewById(R.id.buttonContact); 
myButton.setOnClickListener(new OnClickListener() { 
@Override 
public void onClick(View v) { 
    xmlList = CreateContactXML.getXmlList(); 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    for (int i =1 ; i< xmlList.size(); i++) 
    {Log.e ( null, xmlList.get(i).getAbsolutePath()); 
    final String path ; 
    path = xmlList.get(i).getName(); 
    builder.setTitle("Backup Date"); 
    builder.setItems(i, new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int item) { 
    Toast.makeText(getActivity(), "Restore done for ", Toast.LENGTH_SHORT).show();         
    } 
    }); 
    AlertDialog alert = builder.create(); 
    alert.show(); 
} 
} 
} 
}); 
} 

該列表已創建,我可以loggout其元素。但問題是彈出窗口只包含標題。在警報

回答

1

顯示列表如下:

ArrayList<String> arrfile_path=new ArrayList<String>(); 
    for (int i =1 ; i< xmlList.size(); i++) 
    arrfile_path.add(xmlList.get(i).getAbsolutePath()); 
    builder.setTitle("Backup Date"); 
    builder.setItems(arrfile_path, new DialogInterface.OnClickListener() { 

     // your code here 
    }); 

,因爲目前你逝去的唯一指標(i)至builder.setItems

+0

我有此錯誤: 方法setItems(INT,DialogInterface.OnClickListener)在類型AlertDialog.Builder不適用於參數(ArrayList ,新的DialogInterface.OnClickListener(){}) – Marya