Application类中的BaseAdapter类

时间:2012-07-11 09:17:39

标签: android android-adapter

我写了一个扩展BaseAdapter类的类,代码列表如下:\

public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;

public ArrayList<Drawable> drawablesFromUrl = new ArrayList<Drawable>();

public ImageAdapter(Context c) {
    mContext = c;

}

public void addItem(Drawable item) {
    drawablesFromUrl.add(item);
}

public int getCount() {
    return drawablesFromUrl.size();
}

public Drawable getItem(int position) {
    return drawablesFromUrl.get(position);
}

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

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

    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageDrawable(drawablesFromUrl.get(position));
    return imageView;

}//View getView

}//class ImageAdapter

现在我想将对象“drawablesFromUrl.get(position)”用于另一个活动,其中一个解决方案是在“应用程序类”中编写此类,以便我可以在我的应用程序中的任何位置使用该对象。但不知道如何实施?或者还有其他解决方案可以解决我的问题吗?

谢谢!

1 个答案:

答案 0 :(得分:1)