I've created an activity which will show the multiple-choice list of all the directories in my phone. Till now, I've only managed to show the list of only parent folders. I want when the user clicks of an item (not on the check-box), it should expand to show its sub-folders (also multiple choice list). This is what I've made till now.
Parent1
Parent2
Parent3
Parent4
I want if user selects Parent1, then it expands with sub-folder as:
Parent1
- Sub-Folder1
- Sub-Folder2
Parent2
Parent3
Parent4
Below is my code till now:
public class DirectoryListing extends Activity {
ListView dirlv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directorylisting);
try {
ArrayList<String> dirList = new ArrayList<String>();
dirList = getAllDirList();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, android.R.id.text1,
dirList);
dirlv = (ListView) findViewById(R.id.lvDirList);
dirlv.setAdapter(adapter);
dirlv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
} catch (Exception e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT);
}
}
private ArrayList<String> getAllDirList() {
ArrayList<String> result = new ArrayList<String>();
File home = new File("/");
File[] files = home.listFiles();
for (File file : files) {
if (file.isDirectory()) {
result.add(file.getName());
}
}
return result;
}
}