I'm currently developing an app that records sounds and saves them as *.mp3 files. Once a user is finished recording a sound, he is asked to rename it. After the user is done renaming it, the file is saved to a certain location on the phone as whateverTheUserTypedHere.mp3.
What I currently implemented in the app:
Once the user sets the file name, the name of the file is taken to the second activity (variable called 'filename'). This is the code for making the listview:
//global variables
ListView listView;
ArrayAdapter<String> listAdapter;
ArrayList<String> fileNames = new ArrayList<String>();
//this is inside onCreate
listView = (ListView) findViewById (R.id.mainListView);
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, fileNames);
//this is inside the method that is called everytime file is recorded
public void setFileName(final Editable filename) {
Log.d("2", "Set filename from first activity " + filename);
fileNames.add(filename.toString());
listView.setAdapter(listAdapter);
So this all works as it should now. Everytime a file is recorded and renamed, it is instantly added to listView in a second activity. But this code has a huge flaw - listview's state isn't saved, so everytime I close the app and re-open it, the recorded files are still there on the phone's storage, but listView is nowhere to be found. So what I would need to do is to implement something that will keep saving listview's state everytime it is changed.
What I'm thinking I could do:
I was thinking an easier way would be something else. Instead of adding elements to the listView while recording and then saving listview's state, I could basically build a new listView everytime the activity is opened. I could implement a method that would read a specific directory on my phone and only read *.mp3 files. So that everytime the listview activity would be opened, the listView would be automatically "generated" based on files that are in a specific directory.
What I'm asking for:
I'm new to Android programming, I've been only doing this for 2-3 months. I'd appreciate it a lot if people could give me some pointers on what should I do. Should I keep my currently implemented method that adds listView rows right after file was recorded? If so, how would I then save it's state/how would I save it's added rows? Or would it be easier to implement a method that reads files from a certain directory and then generate a listview each time activity is opened? If so, I would really appreciate some pointers on how to do that, since I've never done anything like that before.
Thank you!