Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android分組數據適配器demo

android分組數據適配器demo

編輯:關於Android編程

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;//標識點名是否成功
	}
	

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved