0

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;
    }
}
Goo
  • 1,318
  • 1
  • 13
  • 31
reiley
  • 3,759
  • 12
  • 58
  • 114

1 Answers1

1

Instead of simple ListView use Expandable Listview.

Go through this link http://about-android.blogspot.in/2010/04/steps-to-implement-expandablelistview.html

and this SO question Android ExpandableListView - Looking for a tutorial

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151