Hi I am working on a simple file browser which is part of my app and I want to delete some files I have added the code even though one item has been deleted, I need a list of files to refresh. This is a code so far and I added a comment in it to the After you delete fileList.notifyDataSetChanged (); I call on , but it does not work for me that what I am doing wrong here? Thanks for any help
Private zero getDir (string directionpath) {item = new ArrayList & lt; String & gt; (); Path = new array list & lt; String & gt; (); File F = New File (Dirpath); File [] files = f.listFiles (); If (DirPath.equals (root)) {item.add (root); Path.add (root); Item.add ("../"); Path.add (f.getParent ()); } (Int i = 0; i & lt; files.length; i ++) {file file = files [i]; Path.add (file.getPath ()); If (file.isDirectory ()) item.add (file.getName () + "/"); Else item.add (file.getName ()); } Arrayadapter & lt; String & gt; FileList = New Array Adapter & lt; String & gt; (This, R. layout.ro, item); SetListAdapter (FileList); } @ Override Protected Zero ListEditClick (ListView L, VV, Final Ent Location, Long Id) {Final File File = New File (Path Gate (Status)); If (file.isDirectory ()) {if (file.canRead ()) getDir (path.get (status)); Else {New AlertDialog.Builder (this) .setIcon (R.drawable.boot) .setTitle ("[" + "file.getName () + '] Can not read the folder!") .setPositiveButton ("OK" Click New DialogInterface.OnClickListener () {@Override Public Zero (DialogInterface dialog, int, which) {}}. Show ();}} and {Final Article [] items = {"info", "rename", "Delete"}; AlertDialog.Builder Builder = New AlertDialog.Builder (this); Builder.setTitle ("+ file.getName ()" option for); builder.setItems (item, new DialogInterface.OnClickListener () {public zero OnClick (DialogInterface dialog, integer item) {if (item == 0) {AlertDialog.Builder Builder = New AlertDialog.builder (Installed.this); SimpleDateFormat SDF = New SimpleDateFormat ("mm / dd / yyyy hh: mm: ss"); builder.setIcon (R.drawable.info) .setTitle (file.getName () + "Info") .setMessage ("Path:" + file. GetPath () + "\ n \ nSize:" + (double) file.length () / 1024 + "MBS +" \ n \ nModified: "+ Sdf.format (file.lastModified ()) .setCancelable (wrong) .setPositiveButton ("OK", New DialogInterface.OnClickListener () {Public Zero onClick (DialogInterface Dialog, Integer ID) {dialog.cancel ();}} ) Show ();. Else if (item == 1) {} else if (item == 2) {AlertDialog.builder Builder = New AlertDialog.Builder (installed; // TODO Change the name of the code Toast.makeText here (Installed.this, "Rename", Toast.LENGTH_SHORT) .show () Add. this); Builder.Setmeasage ("Are you sure to delete" + file.getName () + ""?) .setCancelable (false) .setPositiveButton ("Yes", New DialogInterface.OnClickListener () {Click Public Zero ( DialogInterface dialogue, int id) {file f1 = new file (file.getPath ()); Boolean success = F 1. Delete (); if (! Success) {Toast. "File.getName (), Toast.LnnGHIHART) Show ();} Else {toast.makeText (install.this, file.getName () +" Deleted! ", Toast .LENGTH_SHORT) Show (); } // this The place is where I try to refresh the list file. NotifyDataSetChanged ();}}) .setNegativeButton ("No", New DialogInterface.OnClickListener () {public void onClick (DialogInterface dialogue, int id) {dialog. Show ();}}}. Show ();}}
items , try using
fileList.remove (theItemYouDeleted) . This should remove
items from the
adapter . In other words, you have to remove it from your data and from your
adapter I hope it helps
Comments
Post a Comment