0

Possible Duplicate:
Displaying images from a specific folder on the SDCard using a gridview

I have written the code to get the images and to show them in the listView. But I want to show the images from a particular folder which is located on sdcard . How to do it ?

 public class ItemsList extends ListActivity {

    private ItemsAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.items_list);

        this.adapter = new ItemsAdapter(this, R.layout.items_list_item, ItemManager.getLoadedItems());
        setListAdapter(this.adapter);
    }

    private class ItemsAdapter extends ArrayAdapter<Item> {

        private Item[] items;

        public ItemsAdapter(Context context, int textViewResourceId, Item[] items) {
            super(context, textViewResourceId, items);
            this.items = items;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.items_list_item, null);
            }

            Item it = items[position];
            if (it != null) {
     ImageView iv = (ImageView) v.findViewById(R.id.list_item_image);
                if (iv != null) {
                    iv.setImageDrawable(it.getImage());
                }
            }

            return v;
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        this.adapter.getItem(position).click(this.getApplicationContext());
    }
    }
4

2 回答 2

0

像这样获取图像路径

  Environment.getExternalStorageDirectory().getpath()+File.seperator+"image_name.jpg"

添加

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

对您的清单的此权限

于 2012-09-13T10:43:01.823 回答
0

尝试这个

String path = Environment.getExternalStorageDirectory().getCanonicalFile().toString() + "/yousdcard_path";
于 2012-09-13T10:22:09.263 回答