我有一个gridview,每个网格项中都有一个删除按钮。我的代码如下:
... public ActionResult Index()
{
IEnumerable<CATEGORIES> categories = _categoriesService.GetCategories();
return View(categories);
}
...
generate_photos()
gd_view.setAdapter(new SampleGridViewAdapter(Photos.this));
gd_view.setOnScrollListener(new SampleScrollListener(Photos.this));
gd_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Utilities.custom_toast(Photos.this, "View big", ""+position, "short");
}
});
gd_view.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
{
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3)
{
//Utilities.custom_toast(Photos.this, "LONG Press", ""+position, "short");
return true;
}
});
按下删除按钮后,我想刷新gridview,使图片删除从gridview中消失。我试图调用@Override public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
gridView =new View(context);
gridView = inflater.inflate(R.layout.inflated_gridview, null);
ImageView btn_delete = (ImageView) gridView.findViewById(R.id.btn_delete);
ImageView img_grid = (ImageView) gridView.findViewById(R.id.img_grid);
final TextView tv_ref = (TextView) gridView.findViewById(R.id.tv_ref);
final String url = getItem(position);
Picasso.with(context).load(url).fit().centerCrop().into(img_grid);
tv_ref.setText(""+id.get(position));
btn_delete.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
int id = Integer.parseInt(tv_ref.getText().toString());
Records_Photo n = Select.from(Records_Photo.class).where(Condition.prop("photo_Id").eq(id)).first();
n.delete();
}
});
return gridView;
无法从静态上下文中引用非静态方法
那么在按下删除按钮后如何刷新gridview?现在看来这是一个循环。
谢谢。
答案 0 :(得分:0)
删除图像后,您是否使用adapter.notifyDataSetChanged()方法进行了检查?