1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| public void Load(){
final ListViewCompat list = new ListViewCompat(MainActivity.this);
final String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Imperco";
File f = new File(path);
File files[] = f.listFiles();
if(files[0].isDirectory()) {
Toast.makeText(getBaseContext(), "Dossier vide",Toast.LENGTH_SHORT).show();
return;
}
String filenames[] = new String[files.length];
for (int i=0; i < files.length; i++)
{
filenames[i]=files[i].getName();
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, filenames);
list.setAdapter(adapter);
final AlertDialog.Builder filelist;
filelist = new AlertDialog.Builder(MainActivity.this);
filelist.setView(list);
filelist.setTitle(getString(R.string.AlertMSG_OPEN));
filelist.setNegativeButton(getString(R.string.AlertMSG_CANCEL), new DialogInterface.OnClickListener() {
//Réaction au clic annuler
public void onClick(DialogInterface dialog, int which) {
return;
}
});
final AlertDialog thislist = filelist.create();
thislist.show();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View V, int position, long id) {
String item = (String) list.getAdapter().getItem(position);
filename = item.substring(0, item.indexOf("."));
File selectedfile = new File(path + "/" + filename + ".dat");
read_file(selectedfile);
thislist.dismiss();
}
});
list.setOnItemLongClickListener (new AdapterView.OnItemLongClickListener() {
@Override
final public boolean onItemLongClick(AdapterView<?> arg0, final View arg1,final int position, long arg3) {
AlertDialog.Builder confirm;
confirm = new AlertDialog.Builder(MainActivity.this);
//Pré-rempli le champ avec la valeur actuelle du bouton
confirm.setMessage(getString(R.string.AlertMSG_ConfirmCancel));
confirm.setPositiveButton(getString(R.string.AlertMSG_YES), new DialogInterface.OnClickListener() {
//Réaction au bouton OK
public void onClick(DialogInterface dialog, int which) {
String item = (String) list.getAdapter().getItem(position);
File selectedfile = new File(path + "/" + item);
selectedfile.delete();
thislist.dismiss();
}
});
confirm.setNegativeButton(getString(R.string.AlertMSG_NO), new DialogInterface.OnClickListener() {
//Réaction au clic annuler
public void onClick(DialogInterface dialog, int which) {
//rien
}
});
confirm.show();
return false;
}
});
} |
Partager