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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。