Use listview to display the file list. The initial file directory is "/".
Action when you click an entry in listview:
File file = new file (paths. get (position); <br/> If (file. isdirectory () <br/>{< br/> getfiledir (paths. get (position); <br/>}
Getfiledir method:
Private void getfiledir (string filepath) <br/>{< br/>/* set the current path */<br/> mpath. settext (filepath); </P> <p> items = new arraylist <string> (); <br/> paths = new arraylist <string> (); <br/> file F = new file (filepath); <br/> file [] files = f. listfiles (); </P> <p> If (! Filepath. equals (rootpath) <br/>{< br/>/* the first one is set to [return to the root directory] */<br/> items. add ("back to" + rootpath); <br/> paths. add (rootpath); <br/>/* set the second to [back to upper layer] */<br/> items. add ("back .. /"); <br/> paths. add (F. getparent (); <br/>}< br/>/* add all files to the arraylist */<br/> for (INT I = 0; I <files. length; I ++) <br/>{< br/> file = files [I]; <br/> items. add (file. getname (); <br/> paths. add (file. getpath (); <br/>}</P> <p>/* declare an arrayadapter and use the layout file_row parameter, <br/> and set the adapter to this listactivity */<br/> arrayadapter <string> filelist = <br/> New arrayadapter <string> (this, R. layout. file_row, items); <br/> setlistadapter (filelist); <br/>}
Use the decodefile () method to load image files on the mobile phone Disk:
Mimageview = (imageview) findviewbyid (R. id. mimageview); <br/> file F = new file (filename); <br/> If (F. exists () <br/>{< br/>/* generate a bitmap object and put it in mimageview */<br/> bitmap Bm = bitmapfactory. decodefile (filename); <br/> mimageview. setimagebitmap (BM); <br/>}