码迷,mamicode.com
首页 > 其他好文 > 详细

GridView长按删除

时间:2015-06-09 22:03:51      阅读:161      评论:0      收藏:0      [点我收藏+]

标签: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长按删除

标签:gridview长按删除

原文地址:http://blog.csdn.net/wuxin782515516/article/details/46430243

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!