Android Open Source - RatioImageView Array Adapter Item






From Project

Back to project page RatioImageView.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project RatioImageView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alimuzaffar.ratioimageview.demo;
import java.io.IOException;
//from www.  j av  a2 s .co m
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

// here's our beautiful adapter
public class ArrayAdapterItem extends ArrayAdapter<String> {

    Context mContext;
    int layoutResourceId;
    String data[] = null;

    public ArrayAdapterItem(Context mContext, int layoutResourceId, String[] data) {
        super(mContext, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.mContext = mContext;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null){
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            convertView = inflater.inflate(layoutResourceId, parent, false);
        }

        String resaddr = data[position];

        ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
        
        Drawable d;
    try {
      d = Drawable.createFromStream(mContext.getAssets().open(resaddr), null);
      imageView.setImageDrawable(d);
    } catch (IOException e) {
      Log.e("Adapter", e.getMessage(), e);
    }
        

        return convertView;

    }

}




Java Source Code List

com.alimuzaffar.ratioimageview.RatioImageView.java
com.alimuzaffar.ratioimageview.demo.ArrayAdapterItem.java
com.alimuzaffar.ratioimageview.demo.MainActivity.java