package com.example.adapter;

import java.util.List;

import com.example.kechengbiao.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * 适配课程表的adapter
 * @author user
 *
 */
public class KCAdapter extends BaseAdapter{

	private Context context;
	private List<String[]> list;
	private LayoutInflater inflater;
	
	public KCAdapter(Context context,List<String[]> list){
		this.context=context;
		this.list=list;
		inflater = LayoutInflater.from(context);
	}
	public int getCount() {
		return list.size();
	}
	public Object getItem(int position) {
		return list.get(position);
	}
	public long getItemId(int position) {
		return position;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if(convertView == null){
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.listitem, null);
			viewHolder.btns = new Button[6];
			viewHolder.btns[0]=viewHolder.btn0 = (Button) convertView.findViewById(R.id.btn00);
			viewHolder.btns[1]=viewHolder.btn1 = (Button) convertView.findViewById(R.id.btn01);
			viewHolder.btns[2] = viewHolder.btn2 = (Button) convertView.findViewById(R.id.btn02);
			viewHolder.btns[3] = viewHolder.btn3 = (Button) convertView.findViewById(R.id.btn03);
			viewHolder.btns[4] = viewHolder.btn4 = (Button) convertView.findViewById(R.id.btn04);
			viewHolder.btns[5] = viewHolder.btn5 = (Button) convertView.findViewById(R.id.btn05);
			
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		String[] strs = list.get(position);
		for(int i=0;i<strs.length;i++){   //设置数据
			viewHolder.btns[i].setText(strs[i]);
		}
		return convertView;
	}
	 class ViewHolder{
		    Button[] btns;
	    	public Button btn0,btn1,btn2,btn3,btn4,btn5;
	    	
	    }
}
