1

我在滚动视图中显示属性列表具有 nxn 矩阵视图。这有负载问题(内存不足并需要更多时间来加载)。为了解决这个问题,我尝试了一些解决方案,但无法达到 100%。

  1. 我将列滚动视图更改为列表视图并尝试,但结果显示所有列表视图中的最后一列值。我知道问题是适配器数据集更改会影响所有视图如何克服这个问题?
  2. 最有价值的解决方案是在滚动视图中加载图像,这些图像在屏幕中可见,并且在可见(滚动)变化时我们可以加载图像。如何做到这一点?

我也尝试使用后台进程(doinbackground)进行图像加载。

4

2 回答 2

1

下载gridview或行和列中图像的官方android示例 http://developer.android.com/training/displaying-bitmaps/index.html

于 2013-08-21T05:49:45.903 回答
0

试试这个代码:

public class CustomBaseAdapter extends BaseAdapter {
    Context context;
    List<RowItem> rowItems;

public CustomBaseAdapter(Context context, List<RowItem> items) {
    this.context = context;
    this.rowItems = items;
}

/*private view holder class*/
private class ViewHolder {
    ImageView imageView;
    TextView txtTitle;
    TextView txtDesc;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    LayoutInflater mInflater = (LayoutInflater)
        context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_item, null);
        holder = new ViewHolder();
        holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
        holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
        holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
        convertView.setTag(holder);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }

    RowItem rowItem = (RowItem) getItem(position);

    holder.txtDesc.setText(rowItem.getDesc());
    holder.txtTitle.setText(rowItem.getTitle());
    holder.imageView.setImageResource(rowItem.getImageId());

    return convertView;
}

@Override
public int getCount() {
    return rowItems.size();
}

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

@Override
public long getItemId(int position) {
    return rowItems.indexOf(getItem(position));
}

}

行项目类是:

public class RowItem {
    private int imageId;
    private String title;
    private String desc;


public RowItem(int imageId, String title, String desc) {
    this.imageId = imageId;
    this.title = title;
    this.desc = desc;
}
public int getImageId() {
    return imageId;
}
public void setImageId(int imageId) {
    this.imageId = imageId;
}
public String getDesc() {
    return desc;
}
public void setDesc(String desc) {
    this.desc = desc;
}
public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}
@Override
public String toString() {
    return title + "\n" + desc;
}

}

于 2013-08-21T06:16:58.633 回答