In my application I am using volley imageLoader but there is one issue there I couldn't understand. When I am calling only response.getBitmap and set it as background imageview it's fine, but when I add some code for example System.out.println(response.getBitmap) it crashes. In one word if I call respone.getBitmap only once it's ok, but when twice or more it crashes. What is the problem here?
public class NewsAdapter extends BaseAdapter {
private ArrayList<News> mNewsList;
private DefaultActivity mActivity;
private ImageLoader imageLoader;
private RequestQueue mRequestQueue;
public NewsAdapter(DefaultActivity pActivity, ArrayList<News> newsList){
mActivity = pActivity;
mNewsList = newsList;
mRequestQueue = Volley.newRequestQueue(mActivity);
imageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(
BitmapLruCache.getDefaultLruCacheSize()));
}
private class ViewHolder {
public ImageView networkImageView;
public TextView title;
public TextView description;
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public News getItem(int i) {
return mNewsList.get(i);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
final ViewHolder viewHolder;
final News news = getItem(i);
if (view == null){
final LayoutInflater li = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.orange_news_item, viewGroup, false);
viewHolder = new ViewHolder();
viewHolder.networkImageView = (ImageView)view.findViewById(R.id.imageView);
viewHolder.title = (TextView)view.findViewById(R.id.title);
viewHolder.description = (TextView)view.findViewById(R.id.description);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.title.setText(Html.fromHtml(news.getTitle()));
viewHolder.description.setText(Html.fromHtml(news.getBody()));
imageLoader.get(news.getImageThumbUrl(),new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
viewHolder.networkImageView.setImageBitmap(response.getBitmap());
System.out.println("bitmap="+response.getBitmap());
System.out.println("width="+response.getBitmap().getWidth());
System.out.println("height="+response.getBitmap().getHeight());
}
@Override
public void onErrorResponse(VolleyError error) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
return view;
}
}
onResponse
method? My understanding is that it isn't fully loaded yet, but then, how can i know when it will be? Actually they were 2 questions ;). – Lantha