Subburaj
Subburaj

Reputation: 5192

Bitmap loading in device

In my application I'm using Lazy loading technique.I referred this tutorial . In emulator(android 2.1) image is loading,but in device(android 2.3.4) image is not loading.Only android icon is loading.

my getview code:

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]);

I am totally confused why this is happening in device.Help to solve this.

Upvotes: 1

Views: 296

Answers (2)

Pramod J George
Pramod J George

Reputation: 1723

This works for me. Try this .

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

Also give this permission in manifest file.

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

Upvotes: 3

Pratik Sharma
Pratik Sharma

Reputation: 13415

Test your internet connection before loading images :

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

Declare this function :

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

Make sure with this permissions :

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

Thanks.

Upvotes: 1

Related Questions