0

Androidで画像の遅延読み込みを実装しようとしています。ここでこの優れたチュートリアルに従いました: http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

問題は、エミュレーターで完全に正常に動作することです。エミュレーターでは画像が読み込まれますが、実際のデバイスではデフォルトの画像が表示されるだけです。

私は 6 台の Android デバイスでテストしましたが、うまくいきませんでしたが、エミュレータでは完全にロードされました。

私がどこで間違っているのかについてのアイデアはありますか?

よろしくお願いします!

編集: XML 解析ではなく JSON 解析を使用するようにコードを変更しました。

私のレイジーアダプタークラス:

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;
}
}
4

4 に答える 4

3

この行をコードに入れて試してみてください...

thumb_image.setTag(song.get("thumb"));
imageLoader.DisplayImage(song.get("thumb"), thumb_image);
于 2012-10-30T09:13:39.487 に答える
3

このソリューションを使用する場合

https://github.com/thest1/LazyList

追加する必要があります

android.permission.WRITE_EXTERNAL_STORAGE

アンドロイドマニフェストで

于 2012-11-05T07:57:57.610 に答える
1

私があなたに与えることができる最良の答えは、「遅延読み込みの他のより良い実装を使用する」ことです

于 2012-10-30T09:19:04.243 に答える