我正在实现一个网格视图,其中每个月都有标题(月份)和图像。我正在尝试实现基本适配器,但它似乎不起作用。
GridView stickyGrid = (GridView) findViewById(R.id.show_gridview);
GridViewAdapter adapter = new GridViewAdapter(getBaseContext());
stickyGrid.setAdapter(adapter);
基本适配器实现
public class GridViewAdapter extends BaseAdapter implements
StickyGridHeadersBaseAdapter {
private LayoutInflater inflater;
public GridViewAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
imageUrls.size();
return 0;
}
@Override
public Object getItem(int position) {
return imageUrls.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView holder;
if (convertView == null) {
holder = (ImageView) inflater.inflate(R.layout.item_grid,
parent, false);
} else {
holder = (ImageView) convertView;
}
imageLoader.displayImage(Util.BASE_URL + imageUrls.get(position),
holder, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
String message = null;
switch (failReason.getType()) {
case IO_ERROR:
message = "Input/Output error";
break;
case DECODING_ERROR:
message = "Image can't be decoded";
break;
case NETWORK_DENIED:
message = "Downloads are denied";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
Toast.makeText(getBaseContext(), message,
Toast.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
});
return holder;
}
@Override
public int getCountForHeader(int arg0) {
return datesHeader.size();
}
@Override
public View getHeaderView(int position, View convertView,
ViewGroup parent) {
TextView holder;
if (convertView == null) {
holder = (TextView) inflater.inflate(R.layout.date_header,
parent, false);
} else {
holder = (TextView) convertView;
}
holder.setText(datesHeader.get(position));
return holder;
}
@Override
public int getNumHeaders() {
// TODO Auto-generated method stub
return 0;
}
}
首先,我遇到的问题是它不会为其中任何一个(简单和标题)执行 getView 。我想到的下一件事是如何为特定图像设置标题。我有一个图像 url 的数组列表和另一个标题(月)。请帮助我,因为我已经花了 4 天时间,但找不到任何解决方案。