1

在我的应用程序中,我使用了延迟加载技术。我参考了本教程。在模拟器(android 2.1)图像正在加载,但在设备(android 2.3.4)图像没有加载。只有 android 图标正在加载。

我的getview代码:

if (convertView   == null) {
    //this should only ever run if you do not get a view back            
    LayoutInflater  inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView  = inflater.inflate(R.layout.homelistrow, null); 

    holder = new ViewHolder();
    image = (ImageView) convertView.findViewById(R.id.icon);
    holder.text = (TextView) convertView.findViewById(R.id.name_label);
    convertView.setTag(holder);         
} else { 
    holder = (ViewHolder) convertView.getTag();         
}
//       
imageLoader.DisplayImage(kickerimage[position], image);

// holder.image.setImageBitmap(bitmap);
//////       items=itemsarray[position];
         holder.text.setText(itemsarray[position]);

我完全困惑为什么会在设备中发生这种情况。帮助解决这个问题。

4

2 回答 2

3

这对我有用。试试这个 。

public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {

    View localView = ((LayoutInflater)this.topcouponpage.getSystemService("layout_inflater")).inflate(2130903044, null);
    String str = localOfferCategories.getImagelink();
    if (!str.trim().startsWith("http://"))
      str = "http://" + str;
    ImageView localImageView = (ImageView)localView.findViewById(2131099676);
    this.imgloader.DisplayImage(str, localImageView);

    return localView;
  }
}

还要在清单文件中授予此权限。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2013-01-02T09:08:12.160 回答
1

在加载图像之前测试您的互联网连接:

if (getConnectionState() == false)
    // ErrorHandling("No Internet Connection Found!! Please Try Later on with Internet Connection!");
else
    // perform further execution

声明这个函数:

//To check the internet connection
    private boolean getConnectionState() {
        ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        Log.v("NetworkInfo","NetworkInfo = "+ni);
        if (ni == null)
            return false;
        else
            return true;
    }

确保具有此权限:

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

谢谢。

于 2013-01-02T07:53:55.227 回答