我正在嘗試爲我的listView
創建自定義適配器。這裏是我的CustomAdapter
講座Android自定義適配器listView循環更多
public class CustomAdapter extends ArrayAdapter<Custom>{
private ArrayList<Custom> entries;
private Activity activity;
private int height;
public CustomAdapter(int hei, Activity a, int textViewResourceId, ArrayList<Custom> entries) {
super(a, textViewResourceId, entries);
this.entries = entries;
this.activity = a;
this.height=hei;
}
public static class ViewHolder{
public TextView item1;
public ImageView image;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
LayoutInflater vi =
(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.review_list_m, null);
v.setMinimumHeight(height);
holder = new ViewHolder();
holder.item1 = (TextView) v.findViewById(R.id.name);
holder.image = (ImageView) v.findViewById(R.id.posterView);
v.setTag(holder);
}
else
holder=(ViewHolder)v.getTag();
final Custom custom = entries.get(position);
if (custom != null) {
String imgUrl=custom.getImage();
Log.v("PATH",custom.getcustomBig());
holder.item1.setText(custom.getcustomBig());
}
return v;
}
}
然後我customclass進入只有兩個值。
但以下行日誌中6次
Log.v("PATH",custom.getcustomBig());
喜歡的東西以下
01-09 11:49:34.683: V/PATH(12629): Name 1
01-09 11:49:34.683: V/PATH(12629): Name 2
01-09 11:49:34.683: V/PATH(12629): Name 1
01-09 11:49:34.683: V/PATH(12629): Name 2
01-09 11:49:34.683: V/PATH(12629): Name 1
01-09 11:49:34.683: V/PATH(12629): Name 2
但僅示出2 ListView中的條目。
有什麼奇怪的嗎?因爲我需要在listView
上實現下載圖像腳本。在那種情況下,該圖像會被下載超過1次?
嘗試過。但現在也顯示相同。我試過Log.v(「位置」,「 - 」+位置);然後0和1同時打印。 – ramesh
listView中有多少個元素? –