---
title: "关于 listview 每行绑定一个tag"
author: "yansaibo"
date: "2010-08-03T18:46:54Z"
tags: ["C", "C#", "C++"]
categories: ["移动开发"]
slug: "listview-tag"
draft: false
lastmod: "2010-08-03T18:46:54Z"
id: 728236
url: "https://yansaibo.iteye.com/blog/728236"
---

废话不说 直接代码
记录一下，以后用

```java

 //重写SimpleCursorAdapter
	private class SimpleAdapters extends SimpleCursorAdapter {
	    	MyDataBaseAdapter m_MyDataBaseAdapter;
	    	TextView message;
	    	String[] arr=new String[100];
	        int pos=0;
	     	public SimpleAdapters(Context context, int layout, Cursor c, String[] from,
	    			int[] to) {
	    		super(context, layout, c, from, to);
	    		// TODO Auto-generated constructor stub
	    	}
	    	@Override
	    	public void bindView(View view, Context context, final Cursor cursor) 
	    	{
	    		
	    		/* 构造MyDataBaseAdapter对象 */
	    		m_MyDataBaseAdapter = new MyDataBaseAdapter(context);
	    		/* 取得数据库对象 */
	    		m_MyDataBaseAdapter.open();
	    		// 绑定数据到view ，test
	    		TextView name = (TextView) view.findViewById(R.id.ListTime);
	    		message = (TextView) view.findViewById(R.id.ListMessage);
	    		CheckBox check=(CheckBox)view.findViewById(R.id.CheckboxActivity);
	    		name.setText(cursor.getString(1) + "小时  " + cursor.getString(2)
	    				+ "分钟");
	    		if(cursor.getString(5).equals("1"))
	    		{
	    			check.setChecked(true);
	    		}else
	    			check.setChecked(false);
	    		// 设置tag标记行  	
	    		view.setTag(cursor.getString(0));
	    		arr[pos]=cursor.getString(0);
	    		pos++;
	    		message.setText(cursor.getString(3));
	    		// + view.getTag()
	    		super.bindView(view, context, cursor);
	    		setViewBinder(new SimpleCursorAdapter.ViewBinder() 
	    		{
	    			public boolean setViewValue(View view, Cursor cursor,int columnIndex) {
	    				if (view instanceof CheckBox) {
	    					CheckBox v = (CheckBox) view;
	    					String src=cursor.getString(columnIndex);
	    					if(src.equals("true")){ 
	    						v.setChecked(true);
	    						return true;
	    						}
	    					else if(src.equals("false")){ 
	    						v.setChecked(true);
	    						return true;
	    						}
	    					}
	    				return false;
	    				}
	    			}); 
	    		//利用miCount 获取 数据库最终一个指针的id+1；（闹钟）
	    		miCount=cursor.getInt(0);
	    		miCount++;
	    	}
	    	public View getView( final int position, View convertView,ViewGroup parent) 
	    	{     
	    		convertView = super.getView(position, convertView, parent);       
	    		final CheckBox cb= (CheckBox)convertView.findViewById(R.id.CheckboxActivity);     
	    		cb.setOnClickListener(new OnClickListener()
	    		{           
	    			        
	    			public void onClick(View v) 
	    			{      
	    		    	NotificationInfo notification;	
	    		        // TODO Auto-generated method stub  
	    		    	notification=new NotificationInfo();
	    		    	String pal=arr[position];
	    		    	findData(Integer.valueOf(pal) ,pal,notification);
	    		    	UpData(pal,notification); 	
	    		    	
	    			}                      
	    		});      
	    		return convertView;
	    	}  
	    	public void findData(int ids ,String pal,NotificationInfo notification) {
	    		Cursor cursor = m_MyDataBaseAdapter.fetchData(ids);
	    		if (cursor != null && cursor.getCount() >= 0) 
	    		{
	    			notification.SetHour(Integer.valueOf(cursor.getString(1))) ;
	    			notification.SetMinute(Integer.valueOf(cursor.getString(2)));
	    			notification.SetMessage(cursor.getString(3));
	    		//	notification.SetMessage(":"+pal+":");
	    			if(cursor.getString(4).equals("1"))
	    			{
	    				notification.SetVibrationStatus(true);	    			
	    				
	    			}else
	    			{
	    				notification.SetVibrationStatus(false);
	    			}
	    			 notification.SetMusicName(cursor.getString(6));
	    		    notification.SetMusicPath(cursor.getString(7));
	    		    if(cursor.getString(5).equals("1"))
	    			{
	    		    	CancleAlarm(ids);
	    		    	notification.SetActiveStatus(false);
	    			}else
	    			{
	    				notification.SetActiveStatus(true);
	    				StartAlarm(ids,Integer.valueOf(cursor.getString(1)),Integer.valueOf(cursor.getString(2)));
	    			}

	    		}
	    	//	Toast.makeText(AlarmInfo.this, "finddata"+isVibrate+":"+"activate"+activate , Toast.LENGTH_LONG).show();
	    	}
	        public void UpData(String id ,NotificationInfo notification) 
	    	{
	    		m_MyDataBaseAdapter.updateData(Integer.valueOf(id), notification);
	    	}
	    }

```