标签:gridview长按删除
private boolean isShowDelete = false; @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (isShowDelete) { isShowDelete = false; // 不显示删除图标 } else { isShowDelete = true; // 显示删除图标 } //adapter中定义setIndex方法,将index传递过去 mAdapter.setIndex(position); return true; } <span style="background-color: rgb(255, 0, 0);">BaseAdapter中:</span> public void setIndex(int index) { this.index = index; notifyDataSetChanged(); //及时通知适配器 } <span style="color:#ff0000;"><strong>getView方法:</strong></span> @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = LayoutInflater.from(mContext).inflate(R.layout.grid_item, null); img = (ImageView) convertView.findViewById(R.id.img); name_tv = (TextView) convertView.findViewById(R.id.name_tv); deleteView = convertView.findViewById(R.id.delete_markView); // 如果判断图标显示与不显示 if (index == position) { deleteView.setVisibility(View.VISIBLE);// 显示 } else { deleteView.setVisibility(View.GONE); // 不显示 } img.setBackgroundResource(icons[position]); name_tv.setText(names[position]); return convertView; }
标签:gridview长按删除
原文地址:http://blog.csdn.net/wuxin782515516/article/details/46430243