SaDeGH_F
SaDeGH_F

Reputation: 481

GridView not loading properly?

I have a album feature in my app that user can take/pic images in each page of album.

Photos that are being picked by user will be copied to a specific folder (that is exclusive to that album) and will be named with the page of that album (0.jpg, 1.jpg etc.).

for displaying better, I added a gridview layout for each album which will adapt all of images from that album folder on sdcard. now My problem is that gridview is not adapting image in a correct way. for example if I have 4 images in that folder with 0.jpg to 3.jpg it will load 1.jpg in the first item, then 3.jpg in second and so on. If I click on any images and go to that specific page (I get page number via position int in gridview onclick) it will show the correct photo but not in gridview. for example it will load 2.jpg in position 1 in gridview, but if I click on this it will show 1.jpg in that page).

By the way I tested this on different devices and on some of them this problem is not happening but not all of them and I can't be sure my user device is what.

Gridview Adapter Class:

public class GridViewAdapter extends BaseAdapter {

    private Activity activity;
    private String[] filepath;
    private String[] filename;

    private static LayoutInflater inflater = null;

    public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
        activity = a;
        filepath = fpath;
        filename = fname;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return filepath.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {         
        // TODO Auto-generated method stub
        ImageView i = new ImageView(activity);
        Bitmap bmp = Helper.decodeFile(filepath[position], activity, 128);
        i.setLayoutParams(new GridView.LayoutParams(70, 70));
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setImageBitmap(bmp);
        return i;
    }
}

Upvotes: 0

Views: 177

Answers (1)

greenapps
greenapps

Reputation: 11214

There is nothing in the code you posted that could cause this. But how about sorting some arrays before you instantiate the adapter? Or let the adapter sort the received arrays.

Upvotes: 1

Related Questions