//监听器gv_1.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(GridViewActivity.this, "点击的图片索引=" + position, Toast.LENGTH_SHORT).show(); }}); //长安删除gv_1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { //1-删除数据 //从集合里删除长按的数据 liv.remove(position); //2-刷新GridView视图,看到效果 //通知适配器,数据源改变 im.notifyDataSetChanged(); Toast.makeText(GridViewActivity.this, "删除记录索引="+position, Toast.LENGTH_SHORT).show(); return true;//事件已经被消费,不需要再处理 }});
时间: 2024-10-10 11:34:20