-1
對不起,我的英語。我正在使用適配器,並且我可能會錯誤地使用它。我試圖顯示圖像和textView作爲輸出。 Textview在輸出中正常顯示,但圖像不是。請幫助我,我嘗試了很多次修復它。在DownloadImageTask
加載圖片。在DownloadImageTask
我有類ImageLoader
,我用this tutorial。我沒有任何錯誤,我有什麼(適配器不輸出圖像(安卓)
ArrayList<News> ArrayListNews;
int Resourse;
Context context;
LayoutInflater vi;
public NewsAdapter(Context context, int resource, ArrayList<News> objects) {
super(context, resource, objects);
ArrayListNews = objects;
Resourse = resource;
this.context = context;
vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
convertView = vi.inflate(Resourse, null);
holder = new ViewHolder();
holder.imageview = (ImageView) convertView.findViewById(R.id.imagenews);
holder.nameNews = (TextView) convertView.findViewById(R.id.namenews);
holder.dayNews = (TextView) convertView.findViewById(R.id.daynews);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
new DownloadImageTask(holder.imageview).execute(ArrayListNews.get(position).getImageNews());
holder.nameNews.setText(ArrayListNews.get(position).getNameNews());
holder.dayNews.setText(ArrayListNews.get(position).getDayNews());
return convertView;
}
static class ViewHolder {
public ImageView imageview;
public TextView nameNews;
public TextView dayNews;
}
//this is class set image
private class DownloadImageTask extends AsyncTask<String, Void, String> {
ImageView bmImage;
ImageLoader imgLoader;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
@Override
protected String doInBackground(String... urls) {
String urldisplay = urls[0];
return urldisplay;
}
protected void onPostExecute(String result) {
imgLoader = new ImageLoader(context.getApplicationContext());
imgLoader.DisplayImage(result, bmImage);
}
}
你需要緩存嗎?或者你只是想加載圖片? – Paritosh
@Paritosh我想只是加載圖像。我用魔術棒在列表視圖中顯示圖像 – wqedasdqwdasdasdw