簡體   English   中英

android中的延遲加載僅在模擬器上有效嗎?

[英]lazy loading in android works only on emulator?

我一直在嘗試在Android中實現圖片的延遲加載。 我在這里遵循了這個出色的教程: http : //www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

問題是它在仿真器中工作得很好。 在仿真器中,圖像會加載,但在實際設備上,它們只會顯示默認圖像。

我已經在6個沒有運氣的android設備上進行了測試,但是它們可以完美地加載到Emulator上。

對我要去哪里有任何想法嗎?

在此先感謝大家!

編輯:如果這很重要,我已經修改了代碼以使用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;
}
}

將此行放入您的代碼中並嘗試...

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

如果您使用此解決方案

https://github.com/thest1/LazyList

您需要添加

android.permission.WRITE_EXTERNAL_STORAGE

在android清單中

我能給您的最佳答案是:“使用其他更好的延遲加載實現”,例如fedorvlasov的延遲列表適配器

這將是一個較晚的答案,但有些可以受益。 您參考的教程在模擬器和電話上運行良好。

我認為這里的問題是許可問題。

如果您不將以下行添加到清單文件中,則它可在Emulator上運行,但不能在Phones上運行。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM