2

我无法访问保存图像的文件夹日记,我想将此文件夹中的所有图像显示到画廊中,请给出一些建议如何做

//get the gallery view--------------------------------------------------------------------- 

        Gallery g = (Gallery) findViewById(R.id.gallery);  
        g.setAdapter(new ImageAdapter(this, SDCard()));
//displaying first image on image view      
        Bitmap bm = BitmapFactory.decodeFile( ((List<String>) tFileList).get(0).toString());
        picView.setImageBitmap(bm);

        msg="first image of gallry";
        showToastMessage(msg);


        g.setOnItemClickListener(new OnItemClickListener() 
        {  
            public void onItemClick(AdapterView<?> parent,  View v, int position, long id) 
            { 
                Bitmap bm = BitmapFactory.decodeFile( ((List<String>) tFileList).get(position).toString());
                picView.setImageBitmap(bm);


            }
        });

    }
    private List<String> SDCard()  
    { 
        tFileList = new ArrayList<String>();
        try 
        {




             File dir = Environment.getExternalStorageDirectory();

             File f = new File( dir, "/Diary/");  

             File[] files=f.listFiles();  
             for(int i=0; i<files.length; i++)  
             {  
              File file = files[i];  
              tFileList.add(file.getPath());
             }              
        }  
        catch(Exception e)
        {           
            e.printStackTrace();
            msg="Folder Not Found";
            showToastMessage(msg);

        }       
        return tFileList;
    } 
    public class ImageAdapter extends BaseAdapter 
    {  
        int mGalleryItemBackground;  
        private Context mContext;  
        private List<String> FileList;  

        public ImageAdapter(Context c, List<String> fList) 
        {  
            mContext = c;  
            FileList = fList;  
            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);  
            mGalleryItemBackground = a.getResourceId(  
            R.styleable.Gallery1_android_galleryItemBackground,0);  
            a.recycle();  
        }  
        public int getCount() 
        {  
            return FileList.size();  
        }  

        public Object getItem(int position) 
        {  
            return position;  
        }         
        public long getItemId(int position) 
        {  
            return (position);  
        }     
        public View getView(int position, View convertView,ViewGroup parent) 
        {  
            ImageView i = new ImageView(mContext);  

            Bitmap bm = BitmapFactory.decodeFile(  
              FileList.get(position).toString());  
            i.setImageBitmap(bm);  

            i.setLayoutParams(new Gallery.LayoutParams(70,50));  
            i.setScaleType(ImageView.ScaleType.FIT_XY);  
            i.setBackgroundResource(mGalleryItemBackground);
            return i;  
        }

    }

在这种情况下该怎么办,我哪里出错了

4

0 回答 0