我一直在嘗試在Android中實現延遲加載圖像。我在這裏遵循了這個優秀的教程: http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/Android中的延遲加載只能在模擬器上工作?
問題是它在模擬器中工作得很好。在模擬器中加載圖像,但在真實設備上它們只顯示默認圖像。
我已經在6個android設備上測試過它沒有運氣,但是它們在模擬器上完全加載。
任何想法,我哪裏去錯了?
在此先感謝你們!
編輯:我修改了代碼來使用JSON解析,而不是XML解析,如果這很重要。
我懶適配器類:
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
// Toast.makeText(a, "here too", 500).show();
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
// Setting all values in listview
title.setText(song.get("msg"));
imageLoader.DisplayImage(song.get("thumb"), thumb_image);
return vi;
}
}
你看到logcat中的任何錯誤/異常? –
不是兄弟,在模擬器上它的工作完美沒有任何問題,但是當我嘗試在一個真實的設備上失敗:( –
我會說你要發佈你的LazyAdapter類,這樣我們可以看看。你可以在應用程序中嘗試執行某些日誌記錄,以查看它是否在設備上。下載一個LogCat應用程序並檢查是否有任何東西在設備上拋出錯誤.. – burmat