我的应用程序基于网格视图,该视图显示来自服务器的许多图像。 我试图不要超载服务器,所以我想一次显示20个图像,当用户向下滚动时,应用程序显示更多图像。 我想在Gridview位于屏幕底部时添加一个额外的单元格,然后在服务器完成加载额外图像时使其为GONE,但我找不到解决方案。这里是来自h& m应用程序的图片 - 他们设法弄清楚...我正在尝试构建与他们所做的非常相似的东西。 谁能帮我? 这是我到目前为止的代码.. 谢谢!
public class MyAdapter extends BaseAdapter {
LayoutInflater inflater;
private Context mContext;
// ImageLoader imageLoader;
public MyAdapter(Context c) {
mContext = c;
imageLoader = ImageLoader.getInstance();
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
class ViewHolder {
ProgressBar spinner;
TextView Price;
ImageView imageView;
RelativeLayout Item;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int arg0) {
return mThumbIds[arg0];
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
View grid = convertView;
final ViewHolder holder;
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.list_row_catalog, parent,
false);
holder = new ViewHolder();
holder.spinner = (ProgressBar) grid
.findViewById(R.id.progressBar1);
holder.Price = (TextView) grid.findViewById(R.id.item_text);
holder.imageView = (ImageView) grid.findViewById(R.id.image);
holder.Item = (RelativeLayout) grid.findViewById(R.id.itemGrid);
grid.setTag(holder);
} else {
holder = (ViewHolder) grid.getTag();
}
// SpinnerLoading.setVisibility(View.GONE);
holder.spinner.setVisibility(View.GONE);
holder.Price.setText(String.valueOf(TheAdapterPrice[position]));
imageLoader.displayImage(mThumbIds[position], holder.imageView,
options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
holder.spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
holder.spinner.setVisibility(View.GONE);
}
});
holder.Item.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
gridView.setVisibility(View.GONE);
BigSpinner.setVisibility(View.VISIBLE);
Loading.setVisibility(View.VISIBLE);
Intent intent = new Intent(getActivity(),
Catalog_Store.class);
intent.putExtra("TheItem", mThumbIds[position]);
intent.putExtra("PriceShirt", TheAdapterPrice[position]);
// startActivity(intent);
GetTheIDFromParseServers(intent, TheClassName,
mThumbIds[position]);
}
});
TotalItemDisplay = getCount();
if (continueScrollSelector == true) {
if (position == TotalItemDisplay - 1) {
//this method make the call to the server to add images
AddMoreImages();
// The ScrollSelector is basically how match pictures to
// load every time the user
// scrolls down
ScrollSelector = ScrollSelector + MorePhotosToLoad;
} else {
}
}
return grid;
}