0
我試圖顯示一個列表視圖,其中包含以前從互聯網上下載的圖像以及一些信息。文字信息顯示很好,但imageview不是。我的代碼是:位圖不會出現在ListView中
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.w("MyApp", "Getting View");
View row = convertView;
if(row==null){
LayoutInflater inflater=getLayoutInflater();
row=inflater.inflate(R.layout.list_item, parent, false);
}
ImageView showcase = null;
try{
showcase = new ImageView(ReadingList.this);
}catch(Exception e){
Log.w("MyApp", e.toString());
}
if(showcase!=null){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 3;
Bitmap bm = null;
File dir = new File(PATH + urlIDs[position]);
if(dir.isDirectory()){
Log.w("MyApp","Dir is a directory");
for (File child : dir.listFiles()) {
String path = child.getAbsolutePath();
Log.w("MyApp", path);
bm = BitmapFactory.decodeFile(path, options);
Log.w("MyApp", "See if bm is null");
if(bm!=null){
Log.w("MyApp", "bm!=null");
showcase.setImageBitmap(bm);
break;
}
}
}
}
TextView title =(TextView)row.findViewById(R.id.list_item_text);
TextView url = (TextView) row.findViewById(R.id.list_item_url);
title.setText(Titles[position]);
url.setText(urlPrefixes[position]);
return row;
}
}
對不起它在此刻有點混亂。我可以在logcat中看到,因爲它發現該文件夾中的圖像,它通過bm!=null
檢查,並應設置該圖像作爲如果我沒有弄錯ImageView的內容。我甚至可以在logcat中看到它已移到下一行項目,並且我可以使用eclipse文件管理器來查看實際上是否收到路徑末尾的圖像child.getAbsolutePath
我是什麼做錯了?