我有一個從數據庫中提取圖像URL的列表。一旦它得到的網址,我使用下面的代碼將它們存儲在可繪:不止一次顯示的列表中的圖像
private Drawable LoadImageFromWebOperations(String url){
try{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
然後我保存繪製成一個鏈表,並繼續拉動其他圖像的URL,一旦做到這一點的畫面得到顯示。我遇到的問題是它能夠很好地拖動網頁,但是當它顯示在應用上時,前兩張圖片很好,但當我滾動查看第三張圖片時,它會顯示第一張圖片,對此有何看法? ?
下面是getview和自定義列表代碼:
private class RowData {
protected int mId;
protected String mTitle;
RowData(int id,String title){
mId=id;
mTitle = title;
}
@Override
public String toString() {
return mId+" "+mTitle+" ";
}
}
private class CustomAdapter extends ArrayAdapter<RowData> {
public CustomAdapter(Context context, int resource,
int textViewResourceId, List<RowData> objects) {
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
TextView title = null;
TextView date = null;
TextView detail = null;
ImageView i11=null;
String postDate;
RowData rowData= getItem(position);
if(null == convertView){
convertView = mInflater.inflate(R.layout.newspg, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
title = holder.gettitle();
title.setText(rowData.mTitle);
postDate = getpostDate(news, rowData.mTitle);
Log.i("Date",postDate);
date = holder.getDate();
date.setText(postDate);
i11=holder.getImage(position);
Log.i("pos",Integer.toString(position));
//i11.setImageResource(imgid[0]);
return convertView;
}
private class ViewHolder {
private View mRow;
private TextView title = null;
private TextView date = null;
private TextView detail = null;
private ImageView i11=null;
public ViewHolder(View row) {
mRow = row;
}
public TextView gettitle() {
if(null == title){
title = (TextView) mRow.findViewById(R.id.title);
}
return title;
}
public TextView getDate() {
if(null == date){
date = (TextView) mRow.findViewById(R.id.date);
}
return date;
}
public ImageView getImage(int position) {
if(null == i11){
i11 = (ImageView) mRow.findViewById(R.id.img);
i11.setImageDrawable(newArtists.get(position).getNewsPic());
}
return i11;
}
}
}
看起來好像你正試圖在'ListView'中使用它們,因爲你沒有正確地調用'ListAdapter'中的單元格。 – hwrdprkns 2012-08-07 20:24:53
是的,我使用的是listview,你會推薦我使用什麼? – paul590 2012-08-07 20:39:46
我已經描述了發生的事情,通常它是自定義列表適配器中的錯誤。你發佈的代碼看起來很好。 – Samuel 2012-08-07 20:47:29