リストビューは、JSON、URL から収集して解析した ArrayList からデータを収集します。
各行の左側にアイコンを追加したいのですが、それらはローカルなので、描画可能なフォルダーにあります。解析する必要はありません。ImageView にリンクする ViewHolder にリンクを配置し、xml レイアウトに移動すると、android:src=@drawable/ic_launcher で動作します。私は10の異なる画像が欲しいです。
以下の私のListViewを参照してください:
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 側のローカル イメージ
どんな助けでも大歓迎です。