如何添加SD卡图像的CoverFlow? [英] How can i add sdcard images to coverflow?

查看:255
本文介绍了如何添加SD卡图像的CoverFlow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的CoverFlow与可绘:( 这是我的形象适配器code

  / **不朽的IMAGE_RESOURCE_IDS。 * /
私有静态最后的名单,其中,整数GT; IMAGE_RESOURCE_IDS =新的ArrayList<整数GT;(DEFAULT_LIST_SIZE);

/ **不朽的DEFAULT_RESOURCE_LIST。 * /
私有静态最终诠释[] DEFAULT_RESOURCE_LIST = {
    R.drawable.promo_blue_bg_medium,
    R.drawable.promo_green_bg_medium,
    R.drawable.flow,
    R.drawable.promo_yellow_bg_medium,
    R.drawable.promo_black_bg_medium,

};

/ **位图的地图。 * /
私人最终地图<整型的WeakReference<位图>> bitmapMap =新的HashMap<整型的WeakReference<位图>>();

私人最终上下文的背景下;

/ **
 *创建与资​​源的图像组默认的适配器。
 *
 * @参数方面
 *上下文
 * /
公共ResourceImageAdapter(最终上下文的背景下){
    超();
    this.context =背景;
    setResources(DEFAULT_RESOURCE_LIST);
}

/ **
 *替换与指定的资源。
 *
 * @参数resourceIds
 *资源id的数组。
 * /
公众最终同步无效setResources(最终诠释[] resourceIds){



       字符串ExternalStorageDirectoryPath =环境
         .getExternalStorageDirectory()
         .getAbsolutePath();

       字符串TARGETPATH​​ = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()+/ CamWay /;



       文件targetDirector =新的文件(TARGETPATH​​);


    IMAGE_RESOURCE_IDS.clear();
    对于(最终诠释RESOURCEID:resourceIds){
        IMAGE_RESOURCE_IDS.add(RESOURCEID);
    }
    notifyDataSetChanged();
}

/ *
 *(非Javadoc中)
 *
 * @see android.widget.Adapter#getCount将()
 * /
@覆盖
公共同步INT getCount将(){
    返回IMAGE_RESOURCE_IDS.size();
}

/ *
 *(非Javadoc中)
 *
 * @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(INT)
 * /
@覆盖
受保护的位图createBitmap(最终诠释位置){
    Log.v(TAG创建项目+位置);
    最后的位图位=((BitmapDrawable)context.getResources()。getDrawable(IMAGE_RESOURCE_IDS.get(位置)))
            .getBitmap();
    bitmapMap.put(位置,新的WeakReference<位图>(位图));
    返回的位图;
}
 

}

您看,5绘制上市above.I想负荷5最后说,从folder.How图像可我添加SD卡的图像到code。

我想显示5上次拍摄的照片的CoverFlow。 我希望有人能帮助我。

EDIT(最后code):

 公共类ResourceImageAdapter扩展AbstractCoverFlowImageAdapter {

    // Dosyaalımıbaşlangıç
     公共类ImageAdapter扩展了BaseAdapter {

            私人语境mContext;
            ArrayList的<字符串> ITEMLIST =新的ArrayList<字符串>();

            公共ImageAdapter(上下文C){
             mContext = C;
            }

            空加(字符串路径){
             itemList.add(路径);
            }

         @覆盖
         公众诠释getCount将(){
          返回itemList.size();
         }

         @覆盖
         公共对象的getItem(INT位置){
          // TODO自动生成方法存根
          返回itemList.get(位置);
         }

         @覆盖
         众长getItemId(INT位置){
          // TODO自动生成方法存根
          返回0;
         }

         @覆盖
         公共查看getView(INT位置,查看convertView,ViewGroup中父){
          ImageView的ImageView的;
                如果(convertView == NULL){//如果它不回收,初始化一些属性
                    ImageView的=新ImageView的(mContext);
                    imageView.setLayoutParams(新GridView.LayoutParams(220,220));
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setPadding(8,8,8,8);
                } 其他 {
                    ImageView的=(ImageView的)convertView;
                }

                位图BM =去codeSampledBitmapFromUri(itemList.get(位置),220,220);

                imageView.setImageBitmap(BM);
                返回ImageView的;
         }

         公共位图德codeSampledBitmapFromUri(字符串路径,INT reqWidth,诠释reqHeight){

          位图BM = NULL;
          //第一代code与inJustDe codeBounds = true来检查尺寸
          最后BitmapFactory.Options选项=新BitmapFactory.Options();
          options.inJustDe codeBounds = TRUE;
          BitmapFactory.de codeFILE(路径选择);

          //计算inSampleSize
          options.inSampleSize = calculateInSampleSize(选项,reqWidth,reqHeight);

          与inSampleSize集//德code位图
          options.inJustDe codeBounds = FALSE;
          BM = BitmapFactory.de codeFILE(路径选择);

          返回BM;
         }

         公众诠释calculateInSampleSize(

          BitmapFactory.Options选项,INT reqWidth,诠释reqHeight){
          //原始高度和宽度的图像
          最终诠释身高= options.outHeight;
          最终诠释宽度= options.outWidth;
          INT inSampleSize = 1;

          如果(高度> reqHeight ||宽度GT; reqWidth){
           如果(宽>高度){
            inSampleSize = Math.round((浮动)的高度/(浮点)reqHeight);
           } 其他 {
            inSampleSize = Math.round((浮点)宽/(浮点)reqWidth);
           }
          }

          返回inSampleSize;
         }

        }

           ImageAdapter myImageAdapter;

           //BurasıDosyaalımıbitimi
    / **不朽的标签。 * /
    私有静态最后字符串变量= ResourceImageAdapter.class.getSimpleName();

    / **不朽的DEFAULT_LIST_SIZE。 * /
    私有静态最终诠释DEFAULT_LIST_SIZE = 20;

    / **不朽的IMAGE_RESOURCE_IDS。 * /
    私有静态最后的名单,其中,整数GT; IMAGE_RESOURCE_IDS =新的ArrayList<整数GT;(DEFAULT_LIST_SIZE);

    / **不朽的DEFAULT_RESOURCE_LIST。 * /
    私有静态最终诠释[] DEFAULT_RESOURCE_LIST = {
        R.drawable.promo_blue_bg_medium,
        R.drawable.promo_green_bg_medium,
        R.drawable.flow,
        R.drawable.promo_yellow_bg_medium,
        R.drawable.promo_black_bg_medium,

    };
    私有String [] mFileStrings;
    ArrayList的<字符串> F =新的ArrayList<字符串>();

   公共无效getFromSdcard()
   {
       档案文件=新的文件(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath(),CamWay);

           如果(file.isDirectory())
           {
               文件[]的文件列表= file.listFiles(); //获取filess名单
               mFileStrings =新的String [listFile.length]

               的for(int i = 0; I< listFile.length;我++)
               {
                   mFileStrings [I] = listfile中[I] .getAbsolutePath();
                   f.add(的文件列表[I] .getAbsolutePath()); //添加到数组列表文件的路径
                   的System.out.println(....................................+ mFileStrings [I]) ;
               }
           }
   }

    / **位图的地图。 * /
    私人最终地图<整型的WeakReference<位图>> bitmapMap =新的HashMap<整型的WeakReference<位图>>();

    私人最终上下文的背景下;

    / **
     *创建与资​​源的图像组默认的适配器。
     *
     * @参数方面
     *上下文
     * /
    公共ResourceImageAdapter(最终上下文的背景下){
        超();
        this.context =背景;
        setResources(DEFAULT_RESOURCE_LIST);
    }

    / **
     *替换与指定的资源。
     *
     * @参数resourceIds
     *资源id的数组。
     * /
    公众最终同步无效setResources(最终诠释[] resourceIds){



           字符串ExternalStorageDirectoryPath =环境
             .getExternalStorageDirectory()
             .getAbsolutePath();

           字符串TARGETPATH​​ = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()+/ CamWay /;



           文件targetDirector =新的文件(TARGETPATH​​);


        IMAGE_RESOURCE_IDS.clear();
        对于(最终诠释RESOURCEID:resourceIds){
            IMAGE_RESOURCE_IDS.add(RESOURCEID);
        }
        notifyDataSetChanged();
    }

    / *
     *(非Javadoc中)
     *
     * @see android.widget.Adapter#getCount将()
     * /
    @覆盖
    公共同步INT getCount将(){
        返回IMAGE_RESOURCE_IDS.size();
    }

    / *
     *(非Javadoc中)
     *
     * @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(INT)
     * /
    @覆盖
    受保护的位图createBitmap(最终诠释位置){
        Log.v(TAG创建项目+位置);
        最后的位图位= BitmapFactory.de codeFILE(f.get(位置));

        bitmapMap.put(位置,新的WeakReference<位图>(位图));

        返回的位图;
    }
}
 

编辑2:

启动,然后显示3个项目从开始。当我尝试一下4+项目,它停止。 这是code - getFromSdcard(); INT大小= f.size() - 5; //获取ArrayList的大小,然后按5 //然后循环从该点到你的ArrayList的大小//缩小它来获得最后的5个项目的列表(INT J =大小; J< f.size(); J ++ ){的System.out.println(位置=+ J);的System.out.println(+ f.get(十)文件的路径); }最后的位图位= BitmapFactory.de codeFILE(f.get(位置)); bitmapMap.put(位置,新的WeakReference<位图>(位图));返回位图;

  04-06 21:41:05.013:E / AndroidRuntime(11217):在com.project.smyrna.camway.ResourceImageAdapter.createBitmap(ResourceImageAdapter的.java:152)
 

- 行最后的位图位= BitmapFactory.de codeFILE(f.get(位置));

解决方案

 私有String [] mFileStrings;
 ArrayList的<字符串> F =新的ArrayList<字符串>();

公共无效getFromSdcard()
{
    档案文件=新的文件(android.os.Environment.getExternalStorageDirectory(),您的SD卡);

        如果(file.isDirectory())
        {
            的文件列表= file.listFiles(); //获取文件列表
            的for(int i = listFile.length-5; I< listFile.length;我++)
            {
                    //得到长度减少它5。循环到最后
                mFileStrings [I] = listfile中[I] .getAbsolutePath();
                f.add(的文件列表[I] .getAbsolutePath()); //添加到数组列表文件的路径
                的System.out.println(....................................+ mFileStrings [I]) ;
            }
        }
}
 

您可以在您的SD卡文件夹下的文件的路径。但要确保在SD卡文件夹没有其他文件格式。然后ArrayList中传递给您的适配器中的CoverFlow显示相同

要筛选是png格式,你可以使用下面的

文件

 文件DIR =新的文件(android.os.Environment.getExternalStorageDirectory());
 

然后调用

  walkdir(DIR);

ArrayList的<字符串>文件路径=新的ArrayList<字符串>(); //包含了结尾的所有文件列表

公共无效walkdir(文件目录){
字符串Patternpng =png格式;

文件的文件列表[] = dir.listFiles();

如果(的文件列表!= NULL){
的for(int i = 0; I< listFile.length;我++){

如果(listfile中[I] .isDirectory()){
    walkdir(的文件列表[I]);
} 其他 {
  如果(的文件列表[I] .getName()的endsWith(Patternpng)){
      //做什么都ü希望
      filepath.add(listfile中[I] .getAbsolutePath());
    }
   }
  }
 }
 }
 

从的评论使我假设你需要显示最后5个项目从您的SD卡文件夹

  INT大小= f.size() -  5;
         //获取ArrayList的大小,然后用5减小它
         //然后循环从该点到你的ArrayList大小
         //得到最后5个项目的列表
         对于(INT J =大小; J< f.size(); J ++)
         {
             的System.out.println(位置=+ J);
             的System.out.println(+ f.get(十)文件的路径);
         }
 

您适配器

 公共类MyAdapter扩展AbstractCoverFlowImageAdapter {


@覆盖
公众诠释getCount将(){
    // TODO自动生成方法存根
    返回f.size();
}

@覆盖
公共对象的getItem(INT位置){
    // TODO自动生成方法存根
    返回的位置;
}

@覆盖
众长getItemId(INT位置){
    // TODO自动生成方法存根
    返回0;
}

   公共查看getView(INT位置,查看convertView,ViewGroup中父){
      //膨胀布局
          //做一点事
          //使用编辑2获得最后的5个项目中的数组列表。
          ImageView的形象=(ImageView的)vi.findViewById(R.id.ivv);
          位图B = BitmapFactory.de codeFILE(f.get(位置));
          image.setImageBitmap(B);
    }

  }
 

更新:

  1. 添加只剩下最后5文件路径到您的ArrayList f由于getFromSdcard()

  2. 您的列表视图项数为f.size()

  3. 要取得getview可以使用f.get的路径(位置)()。

在getFromSdcard()

 的for(int i = listFile.length-5; I< listFile.length;我++)
         //从文件夹中添加只剩下最后5文件路径
 

在您的适配器

  @覆盖
 公众诠释getCount将(){
// TODO自动生成方法存根
返回f.size();
}
 

在getView

  ImageView的形象=(ImageView的)vi.findViewById(R.id.ivv);
        位图B = BitmapFactory.de codeFILE(f.get(位置));
        image.setImageBitmap(B);
 

Here is my coverflow with drawables :( This is my Image Adapter Code

    /** The Constant IMAGE_RESOURCE_IDS. */
private static final List<Integer> IMAGE_RESOURCE_IDS = new ArrayList<Integer>(DEFAULT_LIST_SIZE);

/** The Constant DEFAULT_RESOURCE_LIST. */
private static final int[] DEFAULT_RESOURCE_LIST = {
    R.drawable.promo_blue_bg_medium,
    R.drawable.promo_green_bg_medium,
    R.drawable.flow,
    R.drawable.promo_yellow_bg_medium,
    R.drawable.promo_black_bg_medium ,

};

/** The bitmap map. */
private final Map<Integer, WeakReference<Bitmap>> bitmapMap = new HashMap<Integer, WeakReference<Bitmap>>();

private final Context context;

/**
 * Creates the adapter with default set of resource images.
 * 
 * @param context
 *            context
 */
public ResourceImageAdapter(final Context context) {
    super();
    this.context = context;
    setResources(DEFAULT_RESOURCE_LIST);
}

/**
 * Replaces resources with those specified.
 * 
 * @param resourceIds
 *            array of ids of resources.
 */
public final synchronized void setResources(final int[] resourceIds) {



       String ExternalStorageDirectoryPath = Environment
         .getExternalStorageDirectory()
         .getAbsolutePath();

       String targetPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/CamWay/";



       File targetDirector = new File(targetPath);


    IMAGE_RESOURCE_IDS.clear();
    for (final int resourceId : resourceIds) {
        IMAGE_RESOURCE_IDS.add(resourceId);
    }
    notifyDataSetChanged();
}

/*
 * (non-Javadoc)
 * 
 * @see android.widget.Adapter#getCount()
 */
@Override
public synchronized int getCount() {
    return IMAGE_RESOURCE_IDS.size();
}

/*
 * (non-Javadoc)
 * 
 * @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(int)
 */
@Override
protected Bitmap createBitmap(final int position) {
    Log.v(TAG, "creating item " + position);
    final Bitmap bitmap = ((BitmapDrawable) context.getResources().getDrawable(IMAGE_RESOURCE_IDS.get(position)))
            .getBitmap();
    bitmapMap.put(position, new WeakReference<Bitmap>(bitmap));
    return bitmap;
}

}

You see,5 drawable listed above.I wanna load 5 last added images from folder.How can i add sdcard images to that code.

I'm trying to showing 5 last taken photos with coverflow. I hope somebody can help me.

EDIT(last code):

    public class ResourceImageAdapter extends AbstractCoverFlowImageAdapter {

    //Dosya alımı başlangıç
     public class ImageAdapter extends BaseAdapter {

            private Context mContext;
            ArrayList<String> itemList = new ArrayList<String>();

            public ImageAdapter(Context c) {
             mContext = c; 
            }

            void add(String path){
             itemList.add(path); 
            }

         @Override
         public int getCount() {
          return itemList.size();
         }

         @Override
         public Object getItem(int position) {
          // TODO Auto-generated method stub
          return itemList.get(position);
         }

         @Override
         public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
         }

         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
          ImageView imageView;
                if (convertView == null) {  // if it's not recycled, initialize some attributes
                    imageView = new ImageView(mContext);
                    imageView.setLayoutParams(new GridView.LayoutParams(220, 220));
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setPadding(8, 8, 8, 8);
                } else {
                    imageView = (ImageView) convertView;
                }

                Bitmap bm = decodeSampledBitmapFromUri(itemList.get(position), 220, 220);

                imageView.setImageBitmap(bm);
                return imageView;
         }

         public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, int reqHeight) {

          Bitmap bm = null;
          // First decode with inJustDecodeBounds=true to check dimensions
          final BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(path, options);

          // Calculate inSampleSize
          options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

          // Decode bitmap with inSampleSize set
          options.inJustDecodeBounds = false;
          bm = BitmapFactory.decodeFile(path, options); 

          return bm;   
         }

         public int calculateInSampleSize(

          BitmapFactory.Options options, int reqWidth, int reqHeight) {
          // Raw height and width of image
          final int height = options.outHeight;
          final int width = options.outWidth;
          int inSampleSize = 1;

          if (height > reqHeight || width > reqWidth) {
           if (width > height) {
            inSampleSize = Math.round((float)height / (float)reqHeight);    
           } else {
            inSampleSize = Math.round((float)width / (float)reqWidth);    
           }   
          }

          return inSampleSize;    
         }

        }

           ImageAdapter myImageAdapter;

           //Burası Dosya alımı bitimi
    /** The Constant TAG. */
    private static final String TAG = ResourceImageAdapter.class.getSimpleName();

    /** The Constant DEFAULT_LIST_SIZE. */
    private static final int DEFAULT_LIST_SIZE = 20;

    /** The Constant IMAGE_RESOURCE_IDS. */
    private static final List<Integer> IMAGE_RESOURCE_IDS = new ArrayList<Integer>(DEFAULT_LIST_SIZE);

    /** The Constant DEFAULT_RESOURCE_LIST. */
    private static final int[] DEFAULT_RESOURCE_LIST = {
        R.drawable.promo_blue_bg_medium,
        R.drawable.promo_green_bg_medium,
        R.drawable.flow,
        R.drawable.promo_yellow_bg_medium,
        R.drawable.promo_black_bg_medium ,

    };
    private String[] mFileStrings;
    ArrayList<String> f = new ArrayList<String>();

   public void getFromSdcard()
   {
       File file=  new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath() ,"CamWay");

           if (file.isDirectory())
           {
               File[] listFile = file.listFiles();//get list of filess
               mFileStrings = new String[listFile.length];

               for (int i = 0; i < listFile.length; i++)
               {
                   mFileStrings[i] = listFile[i].getAbsolutePath();
                   f.add(listFile[i].getAbsolutePath());//add path of files to array list
                   System.out.println("...................................."+mFileStrings[i]);
               }
           }
   }

    /** The bitmap map. */
    private final Map<Integer, WeakReference<Bitmap>> bitmapMap = new HashMap<Integer, WeakReference<Bitmap>>();

    private final Context context;

    /**
     * Creates the adapter with default set of resource images.
     * 
     * @param context
     *            context
     */
    public ResourceImageAdapter(final Context context) {
        super();
        this.context = context;
        setResources(DEFAULT_RESOURCE_LIST);
    }

    /**
     * Replaces resources with those specified.
     * 
     * @param resourceIds
     *            array of ids of resources.
     */
    public final synchronized void setResources(final int[] resourceIds) {



           String ExternalStorageDirectoryPath = Environment
             .getExternalStorageDirectory()
             .getAbsolutePath();

           String targetPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/CamWay/";



           File targetDirector = new File(targetPath);


        IMAGE_RESOURCE_IDS.clear();
        for (final int resourceId : resourceIds) {
            IMAGE_RESOURCE_IDS.add(resourceId);
        }
        notifyDataSetChanged();
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.widget.Adapter#getCount()
     */
    @Override
    public synchronized int getCount() {
        return IMAGE_RESOURCE_IDS.size();
    }

    /*
     * (non-Javadoc)
     * 
     * @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(int)
     */
    @Override
    protected Bitmap createBitmap(final int position) {
        Log.v(TAG, "creating item " + position);
        final Bitmap bitmap =  BitmapFactory.decodeFile(f.get(position));

        bitmapMap.put(position, new WeakReference<Bitmap>(bitmap));

        return bitmap;
    }
}

EDIT 2 :

it starts and then shows 3 items from beginning .when i try look 4+ item ,it stops. this is code -- getFromSdcard() ; int size= f.size()-5; //get the size of arraylist then decrease it by 5 //then loop from that point to your arraylist size //to get the last 5 items in the list for(int j=size;j<f.size();j++) { System.out.println("Position = "+j); System.out.println("Path of files"+f.get(j)); } final Bitmap bitmap = BitmapFactory.decodeFile(f.get(position)); bitmapMap.put(position, new WeakReference<Bitmap>(bitmap)); return bitmap;

04-06 21:41:05.013: E/AndroidRuntime(11217): at     com.project.smyrna.camway.ResourceImageAdapter.createBitmap(ResourceImageAdapter‌​.java:152)

--line is final Bitmap bitmap = BitmapFactory.decodeFile(f.get(position));

解决方案

private String[] mFileStrings;
 ArrayList<String> f = new ArrayList<String>();

public void getFromSdcard()
{
    File file=  new File(android.os.Environment.getExternalStorageDirectory(),"Your Sdcard");

        if (file.isDirectory())
        {
            listFile = file.listFiles();//get list of files
            for (int i = listFile.length-5; i < listFile.length; i++)
            {
                    //get the length decrease it 5 . loop to last 
                mFileStrings[i] = listFile[i].getAbsolutePath();
                f.add(listFile[i].getAbsolutePath());//add path of files to array list
                System.out.println("...................................."+mFileStrings[i]);
            }
        }
}

You can get the path of files under a folder in your sdcard. But make sure the sdcard folder does not have other file formats. Then pass the arraylist to your adapter to display the same in coverflow

To filter files that are .png you can use the below

 File dir= new File(android.os.Environment.getExternalStorageDirectory());

Then call

walkdir(dir);

ArrayList<String> filepath= new ArrayList<String>();//contains list of all files ending with 

public void walkdir(File dir) {
String Patternpng = ".png";

File listFile[] = dir.listFiles();

if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {

if (listFile[i].isDirectory()) {
    walkdir(listFile[i]);
} else {
  if (listFile[i].getName().endsWith(Patternpng)){
      //Do what ever u want
      filepath.add( listFile[i].getAbsolutePath());
    }
   }
  }  
 }    
 }

From the comment made i assume you need to display last 5 items from your sdcard folder

         int  size= f.size()-5; 
         //get the size of arraylist then decrease it by 5
         //then loop from that point to your arraylist size 
         //to get the last 5 items in the list
         for(int j=size;j<f.size();j++)
         {
             System.out.println("Position = "+j);
             System.out.println("Path of files"+f.get(j));  
         }

Your adapter

 public class MyAdapter extends AbstractCoverFlowImageAdapter {


@Override
public int getCount() {
    // TODO Auto-generated method stub
    return f.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

   public View getView(int position, View convertView, ViewGroup parent) {
      //inflate layout
          //do something
          //use the edit 2 to get last 5 items in the arraylist.
          ImageView image=(ImageView)vi.findViewById(R.id.ivv);
          Bitmap b = BitmapFactory.decodeFile(f.get(position));
          image.setImageBitmap(b);     
    }

  }

UPDATE:

  1. Add only last 5 file paths to your arraylist f in getFromSdcard()

  2. Your listview item count is f.size()

  3. To get the paths you can use f.get(position) in getview().

In getFromSdcard()

        for (int i = listFile.length-5; i < listFile.length; i++)
         // add only last 5 file paths from your folder

In your adapter

@Override
 public int getCount() {
// TODO Auto-generated method stub
return f.size();
}

In getView

        ImageView image=(ImageView)vi.findViewById(R.id.ivv);
        Bitmap b = BitmapFactory.decodeFile(f.get(position));
        image.setImageBitmap(b);

这篇关于如何添加SD卡图像的CoverFlow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆