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;//标识点名是否成功
	}
	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值