在我的应用程序中,我正在使用延迟加载技术。我引用了this tutorial。在模拟器(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]);
我很困惑为什么在设备中发生这种情况。请帮助解决这个问题。
答案 0 :(得分: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" />
答案 1 :(得分: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" />
感谢。