0

I have a little issue with setting an bitmap image as a source of ImageView. Here is the code which I am using :

 BitmapFactory.Options options = new BitmapFactory.Options();
    options.inTempStorage = new byte[16*1024];

    String path = Environment.getExternalStorageDirectory()+"/Stampii/"+objectId+".png";
    Log.i("","path : "+path);

    b = BitmapFactory.decodeFile(path,options);
    if(b==null){
       Log.i("","Bitmap is null");
    }

viewFlow = (ViewFlow) findViewById(R.id.viewflow);
        viewFlow.setAdapter(new ImageAdapter(Cards.this, b),position);

here is how I'm saving the image :

File myDir=new File("/sdcard/Stampii");
                    myDir.mkdirs();

                    String filename = objectId+".png";
                    File file = new File(myDir, filename);
                    FileOutputStream fos;


                    fos = new FileOutputStream(file);
                    fos.write(mediaCardBuffer);
                    fos.flush();
                    fos.close();

ImageAdapter :

ublic class ImageAdapter extends BaseAdapter {

private LayoutInflater mInflater;

private Bitmap bitmap;

public ImageAdapter(Context context, Bitmap image) {
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    bitmap = image;
}

@Override
public int getCount() {
    return 0;
}

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

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.image_item, null);
    }
    ((ImageView) convertView.findViewById(R.id.imgView)).setImageBitmap(bitmap);
    return convertView;
}}

The image is on sdcard i can see it and the name and path are correct. It's just not showing up. Any ideas where is my mistake?

1 Answer 1

3

I would imagine getView is never being called because your adapter is returning that you have 0 items. Try returning a count of 1 or however many instances of that bitmap you want to show.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.