xml - How to populate a spinner in android with file names in a directory? -
i trying create spinner or similar drop down/selector in android. similar opening file, want spinner list of files found in specified directory path.
i.e. --> have directory example1.txt, example2.txt, mymp3.mp3, otheraudio.3pg @ c://path/mystuff
i want spinner populate based on files in directory have option pick of files in directory.
the spinner "display only" functionality. need file names of files in directory. there button contain functionality open selected file spinner.
not sure how go setting up... best file names through java, store in string array in xml spinner read, or other way?
assuming you're talking directory on phone (your reference c://path/mystuff has confused me isn't linux path) don't see there benefits creating xml file list files. can use arrayadapter.createfromresource(...)?
you can following:
.... list<string> filenames = new arraylist<string>(); // populate above list desired path spinner spinner = (spinner) findviewbyid(r.id.spinner); arrayadapter<string> adapter = new arrayadapter<string>(this, r.layout.simple_spinner_item, filenames); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinner.setadapter(adapter); ...
Comments
Post a Comment