Reputation: 6268
I have problem with a Volley and a ListView. Maybe I do not understand how Volley should work... Look here, this is code from my Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRequestQueue = Volley.newRequestQueue(this);
imageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache());
items = createItemList();
expListView = (ListView) findViewById(R.id.listView);
ListAdapter listAdapter = new ListAdapter();
expListView.setAdapter(listAdapter);
}
I setup Volley.newRequestQueue(this)
and ImageLoader
with BitmapLruCache
(the same here).
When in my ListAdapter i override getView()
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = infalInflater.inflate(R.layout.menu_item, null);
final ImageView ivCover = (ImageView) convertView.findViewById(R.id.icCoverThumb);
imageLoader.get(items.get(position).url, ImageLoader.getImageListener(ivCover, R.drawable.ic_launcher, R.drawable.ic_launcher));
return convertView;
}
Here i use imageLoader.get(items.get(position).url, ImageLoader.getImageListener(ivCover, R.drawable.ic_launcher, R.drawable.ic_launcher));
(is tender spot here?).
Thumbs was loaded but smth went wrong: when app starts first time, the first item in the list view has duplicate ico with one of the icons from the other line - http://prntscr.com/1wmrck
Thanks!
Upvotes: 2
Views: 2050
Reputation: 1477
Difficult to reproduce without more information, but I would recommend the use of NetworkImageView
to load thumbnails from the network and btw, I would use a "ViewHolder" to improve the performance of your ListView
This is a sample ArrayAdapter
to show tweets on a ListView
...
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.tweet_list_item, null);
holder = new ViewHolder();
holder.imageView = (NetworkImageView) convertView.findViewById(R.id.twitterUserImage);
//set more views (username, text, date ...)
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//get the current element from the data array
Tweet currentTweet = getItem(position);
//set data into the views
holder.imageView.setImageUrl(currentTweet.getUser().getProfileImageUrl(), VolleyManager.getImageLoader());
//...
return convertView;
}
private static class ViewHolder {
private NetworkImageView imageView;
//other views...
}
Upvotes: 2