Custom adapters Browse all files in the SD card directory

Source: Internet
Author: User
Tags stub tostring

Class Myadapter extends Baseadapter {
Private Layoutinflater Minflater;
Private Bitmap MIcon1;
Private Bitmap MIcon2;
Private Bitmap MIcon3;
Private Bitmap MIcon4;
Private list<string> items;
private list<string> paths;

Public Myadapter (context context, list<string> it, list<string> PA) {
Minflater = Layoutinflater.from (context);
items = it;
paths = PA;
MIcon1 = Bitmapfactory.decoderesource (Context.getresources (),
R.DRAWABLE.BACK01);
MIcon2 = Bitmapfactory.decoderesource (Context.getresources (),
R.DRAWABLE.BACK02);
MIcon3 = Bitmapfactory.decoderesource (Context.getresources (),
R.drawable.folder);
MIcon4 = Bitmapfactory.decoderesource (Context.getresources (),
R.drawable.doc);
}

@Override
public int GetCount () {
TODO auto-generated Method Stub
return Items.size ();
}

@Override
Public Object getitem (int position) {
TODO auto-generated Method Stub
return Items.get (position);
}

@Override
public long getitemid (int position) {
TODO auto-generated Method Stub
return position;
}

@Override
Public View getview (int position, View convertview, viewgroup par) {
Viewholder holder;
if (conve Rtview = = null) {
Convertview = minflater.inflate (R.layout.file_row, null);
Holder = new Viewholder ();
Holder. Text = (TextView) Convertview
. Findviewbyid (R.id.txt_path);
Holder.icon = (imageview) Convertview
. Findviewbyid (R.ID.ICON_FILE_LIST1);
Convertview.settag (holder);
} else {
Holder = (viewholder) convertview.gettag ();
}
File f = new file (paths.get (position). ToString ());
if (("B1"). Equals (Items.get (position). ToString ()) {
Holder.text.setText ("Back To/");
Holder.icon.setImageBitmap (MIcon1);
} else if (("B2"). Equals (Items.get (position). ToString ()) {
Holder.text.setText ("Back to ...");
Holder.icon.setImageBitmap (MIcon2);
} else {
Holder.text.setText (F.getname ()),
if (F.isdirectory ()) {
Holder.icon.setImageBitmap (mIcon3);
} else {
Holder.icon.setImageBitmap (mIcon4);
}
}
return convertview;
}

Public final class Viewholder {
Public TextView text,
Public imageview icon;
}
}

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.