首页 > 代码库 > android分组数据适配器demo
android分组数据适配器demo
private class CheckedNameDeceiveInfoAdapter extends BaseAdapter{ @Override public boolean isEnabled(int position) { if (position == 0) { return false; } else if (position == (mSuccessCheckNameInfos.size() + 1)) { return false; } return super.isEnabled(position); } @Override public int getCount() { // TODO Auto-generated method stub return mSuccessCheckNameInfos.size()+mFailCheckNameInfos.size()+2; } @Override public Object getItem(int position) { if(position==0){ return position; }else if(position==mSuccessCheckNameInfos.size()+1){ return position; }else if(position<=mSuccessCheckNameInfos.size()){ //点名成功信息 int newPosition=position-1; return mSuccessCheckNameInfos.get(newPosition); }else{ //点名失败信息 int newPosition=position-1-1-mSuccessCheckNameInfos.size(); return mFailCheckNameInfos.get(newPosition); } } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { DeviceInfo info=null; if(position==0){ TextView tv = new TextView(getApplicationContext()); tv.setTextSize(18); tv.setTextColor(Color.BLUE); tv.setBackgroundResource(android.R.color.darker_gray); tv.setText("点名成功 (" + mSuccessCheckNameInfos.size() + "个)"); return tv; }else if (position == (mSuccessCheckNameInfos.size() + 1)) { TextView tv = new TextView(getApplicationContext()); tv.setTextSize(18); tv.setTextColor(Color.BLUE); tv.setBackgroundResource(android.R.color.darker_gray); tv.setText("点名失败 (" + mFailCheckNameInfos.size() + "个)"); return tv; }else if(position<=mSuccessCheckNameInfos.size()){ //返回点名成功信息 info=mSuccessCheckNameInfos.get(position-1); }else { //点名失败信息 info=mFailCheckNameInfos.get(position-1-1-mSuccessCheckNameInfos.size()); } View view=null; ViewHolder2 holder=null; if(convertView!=null&& convertView instanceof RelativeLayout){ view=convertView; holder=(ViewHolder2) view.getTag(); }else{ view=View.inflate(CheckNameActivity.this,R.layout.check_name_item,null); holder=new ViewHolder2(); holder.head=(ImageView) view.findViewById(R.id.iv_head_check_name_success_fail); holder.tvName=(TextView) view.findViewById(R.id.tv_name); holder.tvMac=(TextView)view.findViewById(R.id.tv_addr_info); view.setTag(holder); } holder.tvName.setText(info.getmDeviceName()); holder.tvMac.setText(info.getmDeviceMacAddr()); return view; } } static class ViewHolder2{ TextView tvName;//显示设备名 TextView tvMac;//显示点名是否成功 ImageView head;//标识点名是否成功 }
android分组数据适配器demo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。