I am developing a Note App that store file in external sd card. File Management is also a part of app. App allow user to create folder. I use this code.
file.mkdir();
After that I refresh my ListView;
I can see newly created folder in listView. But i can't acess it( click it) immediately. I have to wait for a while to be able to access it. Please help me out..
The problem is solved.
Before setting new adapter to listView, set null to setAdapter().
I add
listView.setAdapter(null);//this make listView empty
listView.setAdapter(adapter);//fill listView with new Data..
Related
I'm creating a simple file explorer on Android Studio, and I wonder which one of the following implementations is the best:
My solution:
I have an activity called MainActivity that displays my list of files, and each time the user clicks on a directory, it creates a new MainActivity (and the onCreate method gets the new list of files, ...).
Correction:
In a correction from a tutorial, I found that when the user clicks on a directory, instead of starting a new activity, the code keeps the current one and changes everything (clear the list and fill it with new files, change the title...).
Is there a solution that is better than the other ? Is it more efficient to keep always the same activity ?
Thanks for any help.
Keep a single activity no question about it !
When a user clicks an item you build your data-source based on the newly selected path. Make sure to distinct between files and directories. Then simply call notifyDataSetChanged and thats it !
To query the file system there are two ways:
The easy - use Java File.listFiles()
The hard - run shell command Runtime.getRuntime().exec( "ls -la" ) and parse response.
There are many open source projects on github for the subject. Example:
Amaze File Manager
I would like to create a button that when clicked will go to a class that displays all media files from an SD card using a ListView.
After selecting from the list it will then return the filename selected to the main class. IF the returned file is an image file, it will be displayed in an ImageView and if the returned file is an audio file, it'll display and on click play?
You may find it interesting to use a library to consult the files in a directory and display it. This can save you lots of work if the requirements of your application permits. There are a lot of libraries for this pourpose, for example:
https://github.com/bartwell/ExFilePicker
Hope it helps you!!
hi i want make simple file explorer which can display all folder of sdcard using listview and only display image file using gridview.i do all of this thing very well.Display in screen shot.but after this i handle the all folder structure of sdcard.also revers process will be handle successfully.but problem is there
when i click on the system folder like .android_secure ,secure ,asec then display Null pointer Exception.but i handle this if folder is empty then display Message folder is empty.
so what i can do now?how to handle this problem.
first i want hide this folder means does not display in listview. but can`t success.
please give me the way.
First Error Image
Now I add Next Point in this that i want to delete specific folder.so i use file.delete() but if the folder is not empty then what to do?
i also want delete this folder with all contain it`s possible with android2.2?
If you use File,
try
File file;
if(file.isfolder && file.list[] != null && file.isreadable()){ // check read,write access
imageView.setVisible(Visible)
}else{
// hide your list item data
}
or first check adapter data and then put it into adapter.
File files
// ... check files
Adapter adapter = new Adapter(files)
setListAdapter(adapter)
I have a layout where users can add buttons and place them where they want.
I want to allow the user to save their layout so that it is loaded the next time they open the app.
Does anyone know if I can save the file on the sdcard? Alternatively I could use some kind of layout.getXml() method and put it in the database my app uses.
Thanks in advance
There is no file to save when you are generating a layout via code. You will have to create your own file format, which could be saved to the SD card or inserted into a database.
You can us savedInstaceState() method with the same type object as parameter .
there load the ui you want at the time of reloading.
In onCreate() method put a condition whethere that savedInstaceState obj is null or not . if not then call the LoadUI().
If I were you, I would create a class holding all the information about this layout and buttons. And write every information of the class to a file with JSONWriter. When the app has opened I just read the file and recreate the arrays using JSONObjects.
I am new to this android application development.
I have a audio files in a particular directory. I want to list the those audio files in a listView.
please tell me how to do this activity.
Create a File object representing your directory on the SDcard and call appropriate File#list() variant to get list of all the files in that directory. You will get names of the files in a String[].
Create an Adapter class and pass this String array to it. Make a ListView and back it up by this custom Adapter.You can refer examples in API demos or this tutorial for the same