1.i有一个网格视图,我必须从数据库获取图像路径,图像是可绘制的 我的问题是,当我向下滚动网格视图图像变得不可见时,我有以下适配器 什么帮助????
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class GridViewAdapter extends BaseAdapter {
private Activity context;
List<Fotota> list_popupBarBackGround;
static final int ON_STICKER_LAYOUT=4;
private static ViewHolder holder;
private LayoutInflater l_Inflater;
public GridViewAdapter(Activity context, List<Fotota> list_popupBarBackGround) {
this.context = context;
this.list_popupBarBackGround = list_popupBarBackGround;
l_Inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return list_popupBarBackGround.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
convertView = l_Inflater.inflate(R.layout.listview_griditem, null);
holder = new ViewHolder();
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.imageView.setImageResource(context.getResources()
.getIdentifier(list_popupBarBackGround.get(position).getThumbnail(), "drawable",context.getPackageName()));
return convertView;
}
private static class ViewHolder {
ImageView imageView;
}
答案 0 :(得分:0)
您需要返回getItem()
中的位置。
同时在ViewHolder()
方法中移除getView()
的两个实例。只需宣布一次。
@Override public Object getItem(int position) { return list_popupBarBackGround.get(position); } @Override public long getItemId(int position) { return position; }
答案 1 :(得分:0)
在适配器
中覆盖这两个方法 @Override
public Object getItem(int position) {
return list_popupBarBackGround.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
答案 2 :(得分:0)
使用Recyclerview而不是Gridview。
recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));