列表视图从 ArrayList 收集数据,该 ArrayList 已从 JSON、URL 收集数据并对其进行解析。
现在我想在每一行的左侧添加图标,但它们是本地的,所以在我的可绘制文件夹中。它们不需要被解析。我在链接到 ImageView 的 ViewHolder 中放置了一个链接,如果我转到我的 xml 布局,我可以 android:src=@drawable/ic_launcher 并且它将起作用。我想要10个不同的图像。
请参阅下面的列表视图:
class FancyAdapter extends ArrayAdapter<idData> {
FancyAdapter() {
super(getApplicationContext(), android.R.layout.simple_list_item_1, arrayOfBooks);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.row_full, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
else {
holder = (ViewHolder)convertView.getTag();
}
holder.populateFrom(arrayOfBooks.get(position));
return(convertView);
}
class ViewHolder {
public TextView id = null;
public TextView title = null;
public TextView link = null;
public ImageView image = null;
ViewHolder(View row) {
id = (TextView) row.findViewById(R.id.id);
title = (TextView) row.findViewById(R.id.title);
link = (TextView) row.findViewById(R.id.link);
image = (ImageView) row.findViewById(R.id.imageView);
}
void populateFrom(idData r) {
id.setText("ID: " + r.id);
title.setText(r.title);
link.setText("URL: " + r.link);
image.setImageResource(R.drawable.ic_launcher);
}
}
}
我尝试添加它以查看是否可以链接它,但它不起作用:
public static final Integer[] images = { R.drawable.ic_action_overflow,
R.drawable.ic_launcher, R.drawable.bg_main, R.drawable.ic_launcher};
有任何想法吗?服务器端 JSON 端的本地图像
任何帮助表示赞赏。