So I am writing an Android app which performs certain calculations which involve dozens of variables, and I want to let the user store the value of these variables in a file so that they can load those values into the calculation again in the future, without having to type them in all over again.
Ideally, what I want is to be able to have the users store their the values inside their device, presumably as files, and then browse these files later on, picking which ever one they want to upload into the calculations.
However, I’m not sure what the best way to implement this “browsing” is. My current, most likely primitive idea is to have a single file, always present, that stores the names of all the other files the user has saved, and a fragment that reads that one static file and displays all those file names in Buttons for the user to select at will. Is there a more robust or intuitive way of letting users browse available files or sets of data that doesn’t require such manual tinkering?
When creating the files use the
openFileOutput(String name, int mode)method.NOTE, the name must be file name only (no path) and the file will be created in the app’s own internal ‘files’ directory.
When you want to enumerate the files, use
getFilesDir()to get aFileobject with the path of the ‘files’ directory, then calllistFiles()to get an array of files in that directory (asFile[]).Iterate through the
File[]to get the names of all files and use those to populate anArrayAdapter<String>and use that to populate aListView.When a user selects a file from the list retreive the file name from the selected list item then use
openFileInput(String name)to open the file. NOTE, againnameis file name only without a path.