Reputation: 332
I have an Array list of xml files (xmlList) created like that :
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);
And then want to show the elements of this list in a pop up window (after clicking in a button: button contact ) .So I wrote this code
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();
}
}
}
});
}
The List is created and i can loggout its elements. But the problem is that the pop window contains only the title .
Upvotes: 0
Views: 832
Reputation: 132972
Show List in Alert as:
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
});
because currently you are passing only index(i) to builder.setItems
Upvotes: 1