Android File Operations

Source: Internet
Author: User

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/>} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.