У меня есть ListView
, внизу есть кнопка «Загрузить еще». При нажатии кнопки «Загрузить больше» добавьте данные с удаленного устройства, чтобы добавить набор данных адаптера списка. Каждый элемент списка имеет большую фотографию, которую можно загрузить с помощью ImageLoader. При использовании адаптера notifyDataSetChanged
все элементы будут получать вид и все элементы будут перерисованы, большая фотография будет перерисована, пользовательский интерфейс будет обновлен. Изменен ли метод уведомления о новом добавленном элементе и перезагружается только новый элемент?
Мой адаптер такой:
public class PhotoSquareAdapter extends BaseAdapter
{
private List<PhotoRecom> data;
public PhotoSquareAdapter(List<PhotoRecom> data)
{
this.data = data;
}
public void addList(List<PhotoRecom> d) {
for (PhotoRecom n : d) {
data.add(n);
//addView(data.size() - 1);
}
super.notifyDataSetChanged();
}
@Override
public int getCount() {
return data.size();
}
@Override
public PhotoRecom getItem(int position) {
if (position >= getCount())
return data.get(getCount() - 1);
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final PhotoRecom item = getItem(position);
final ViewHolder holder;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.photo_square_list_item, parent, false);
holder = new ViewHolder();
holder.iv_photo_square_listitem_head_thumbnail = (ImageView) convertView.findViewById(R.id.iv_photo_square_listitem_head_thumbnail);
holder.iv_photo_square_city = (ImageView) convertView.findViewById(R.id.iv_photo_square_city);
holder.tv_photo_square_nick = (TextView) convertView.findViewById(R.id.tv_photo_square_nick);
holder.tv_photo_square_title = (TextView) convertView.findViewById(R.id.tv_photo_square_title);
holder.tv_photo_square_like = (TextView) convertView.findViewById(R.id.tv_photo_square_like);
holder.iv_photo_square_photo = (ImageView) convertView.findViewById(R.id.iv_photo_square_photo);
holder.tv_photo_square_saw = (TextView) convertView.findViewById(R.id.tv_photo_square_saw);
holder.tv_photo_square_chat = (TextView) convertView.findViewById(R.id.tv_photo_square_chat);
holder.pb_loading_img = (ProgressBar) convertView.findViewById(R.id.pb_loading_img);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
imageLoader.displayImage((url + item.getPhoto()), holder.iv_photo_square_photo, options);
//...
return convertView;
}
private class ViewHolder {
ImageView iv_photo_square_listitem_head_thumbnail;
ImageView iv_photo_square_city;
TextView tv_photo_square_nick;
ProgressBar pb_loading_img;
TextView tv_photo_square_title;
TextView tv_photo_square_like;
ImageView iv_photo_square_photo;
TextView tv_photo_square_saw;
TextView tv_photo_square_chat;
}
}