从活动中动态更改适配器中的imageview

时间:2014-02-27 06:15:02

标签: android android-listview imageview android-custom-view custom-adapter

我有一个自定义列表适配器,其中包含n个ImageView。我想通过调用触发器(不使用任何onclick)从活动更改列表中特定项目的图像源。我正在获取需要更改的项目的位置,但我不知道如何获取该特定位置的ImageView。请帮我解决这个问题。

public AppCustomAdapter(Context context, int resource, AppCustomClass[] data) {

        super(context, resource, data);
        this.context = context;
        this.layoutResourceId = resource;
        this.data = data;

    }

    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public View getView(final int pos, View convertView, ViewGroup parent) {
        View row = convertView;

        final ViewHolder holder;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context)
                    .getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();

            holder.tv = (TextView) row.findViewById(R.id.showText);
            holder.iv = (ImageView) row.findViewById(R.id.showImage);

            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }

        AppChatClass cfile = data[pos];

        holder.textView.append(cfile.txt);
            if(cfile.img_res < 10)
            holder.imageView.setImageResource(R.drawable.lessten);
            else if(cfile.img_res > 10)
            holder.imageView.setImageResource(R.drawable.greaterten);

        return null;
     }

    public static class ViewHolder {
        public TextView tv;
        public ImageView iv;
    }

0 个答案:

没有答案
相关问题