I have a ListView
which displays in every row an image pulled from the internet, and a string.
In general it works fine. However I want to take control on the way when the views (rows) are inflated. By default when the row is visible the getView()
method of the adapter is called.
This of course is not one of the best behaviours because if I have a ListView
with several hundreds of records, and I need to reach the ones at the bottom, while scrolling the ListView
, the getView()
method will be invoked for every row until I reach the footer.
So I want to call getView only after scrolling and the ListView is in paused/idle state, but I do not have idea how to go about this:
Here's how I begun:
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState==SCROLL_STATE_IDLE){
// Invoke get view only on visible items
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
});
This is the getView of my adapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, parent, false);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.textView);
holder.image = (ImageView) convertView.findViewById(R.id.imageView);
holder.position = position;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(data.get(position).getTitle());
holder.image.setImageResource(R.drawable.ic_launcher);
new LoadImageAsync(data.get(position).getUrl(), holder.image).execute();
return convertView;
}
Please, give me some directions on where should I look in order to achieve this: Call getView() only after scrolling, and only for visible items.