博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android自定义单选,自定义选中状态
阅读量:5962 次
发布时间:2019-06-19

本文共 2666 字,大约阅读时间需要 8 分钟。

如图,此布局用GrildView实现,弹出框由Activity的dialog样式实现。

屏蔽系统GrildView点击背景黄色:

grildview.setSelector(new ColorDrawable(Color.TRANSPARENT));

实现数据源自定义Adapter

public class PeoPleNumAdapter extends BaseAdapter {    public List
FiltArray; public static HashMap
isselected; LayoutInflater inflater; int pos; public PeoPleNumAdapter(Context context,List
PeopleNumList,int pos) { super(); inflater = LayoutInflater.from(context); this.FiltArray = PeopleNumList; this.pos = pos; isselected = new HashMap
(); initData(); } public void initData() { for (int i = 0; i < FiltArray.size(); i++) { PeopleNum peo = FiltArray.get(i); if(i!=pos) getIsSelected().put(i, false); else getIsSelected().put(i, true); } } @Override public int getCount() { // TODO Auto-generated method stub return FiltArray.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return FiltArray.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View view, ViewGroup parent) { // TODO Auto-generated method stub if (view == null) { view = inflater.inflate(R.layout.people_grild, null); TextView spec = (TextView) view.findViewById(R.id.peoplenum); final ImageView img = (ImageView) view.findViewById(R.id.numselect); PeopleNum peo = FiltArray.get(position); spec.setText(peo.getNum()); if (getIsSelected().get(position)) { img.setVisibility(View.VISIBLE); } else { img.setVisibility(View.GONE); } } return view; } public static HashMap
getIsSelected() { return isselected; } public static void setIsSelected(HashMap
isSelect) { PeoPleNumAdapter.isselected = isSelect; }}

Activity中实现点击:

grildview.setOnItemClickListener(new OnItemClickListener() {            @Override            public void onItemClick(AdapterView
parent, View view, int position, long id) { // TODO Auto-generated method stub PeoPleNumAdapter.getIsSelected().put(position, true); adapter = new PeoPleNumAdapter(context, PeopleNumList, position); grildview.setAdapter(adapter); } });

 

 

转载地址:http://spjax.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14
查看>>
amazon 设计 10 puzzle.
查看>>
利用单臂路由实现VLAN间路由
查看>>
恢复数据库遇到ORA-0600故障
查看>>
Oracle创建类似mysql AUTO_INCREMENT自增列
查看>>
Configuration Section Designer for VS2017
查看>>
python 中关于struct处理二进制数据
查看>>
Tomcat配置
查看>>
我的友情链接
查看>>
云客户端重在连接
查看>>
Linux和AIX下添加定时任务
查看>>
HTML+DOM与XML+DOM之间的区别与联系
查看>>
VS2012 发布网站步骤
查看>>
dubbo的服务提供者provider启动的一些理解
查看>>
Java之品优购部署_day01(2)
查看>>
[20171227]表的FULL_HASH_VALUE值的计算.txt
查看>>
[20190415]关于shared latch(共享栓锁).txt
查看>>
设计读书笔记
查看>>
Linux命令总结(转)
查看>>