2012-10-26 47 views
0

我一直在嘗試在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; 
} 
} 
+1

你看到logcat中的任何錯誤/異常? –

+0

不是兄弟,在模擬器上它的工作完美沒有任何問題,但是當我嘗試在一個真實的設備上失敗:( –

+3

我會說你要發佈你的LazyAdapter類,這樣我們可以看看。你可以在應用程序中嘗試執行某些日誌記錄,以查看它是否在設備上。下載一個LogCat應用程序並檢查是否有任何東西在設備上拋出錯誤.. – burmat

回答

3

如果您使用此解決方案

https://github.com/thest1/LazyList

你需要添加

android.permission.WRITE_EXTERNAL_STORAGE

在Android清單

+0

這是錯誤,顯然是教程我正在使用也需要的權限,我完全忘了看到它!謝謝大量指出!雖然模擬器加載沒有許可的拇指怪:P –

+0

我很高興我可以幫助:) – Stipe

3

把這一行在你的代碼,並嘗試...

thumb_image.setTag(song.get("thumb")); 
imageLoader.DisplayImage(song.get("thumb"), thumb_image); 
+0

This did not work! –

0

這將是一個遲到的回答但有些可以受益。 您引用的教程在仿真器和手機上運行得非常好。

我覺得這裏的問題是一個權限問題。

如果你不把以下行放到你的清單文件中,它可以在模擬器上工作,但不能在手機上工作。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />