Android listfiles not refreshed when files changes
my app has a ListActivity to let the user choose a file from a list generated by listFiles().
File f=null;
File[] files = null;
f= new File(BOOKPATH);
files = f.listFiles();
item = new ArrayList<String>();
for(int i=files.length-1; i >= 0; i--){
File file = files[i];
item.add(file.getName());
}
It works well, and when the user clic开发者_开发知识库ks on an entry, an activity is launched, then the user can edit the file. When the user quits the editing Activity, the edited content is saved in a new file with a new name, and the first selected file is deleted.
Then the same code to get the new list of files is called again, on the onResume() of the first Activity.
The code is well executed, but the function listFiles() return the ancient list, like if a buffer were not refreshed.
A strange thing is that the correct list of files is returned when I change orientation on the android device, and onResume() is called again.
I also tried to restart the activity by different ways to obtain the same behaviour, with no succes.
Thanks in advance for helping.
Try notifyDataSetChanged()
to reload the list.
精彩评论