package com.zhao.adapter;
import java.util.List;
import com.zhao.ext.R;
import com.zhao.model.TgName;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ListAdapter extends BaseAdapter{
private List<TgName> tlist;
private Context context;
private LayoutInflater inflater;
private final int ITEM1 = 0;
private final int ITEM2 = 1;
private final int ITEMCOUNT = 2;
public ListAdapter(List<TgName> tlist, Context context) {
super();
this.tlist = tlist;
this.context = context;
this.inflater = LayoutInflater.from(context);
}
@Override
public int getItemViewType(int position) {
if(tlist.get(position).isFlag()){
return ITEM1;
}else{
return ITEM2;
}
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return ITEMCOUNT;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return tlist.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return tlist.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
holder = new ViewHolder();
if(getItemViewType(position) == ITEM1){
convertView = inflater.inflate(R.layout.item1_layout, null);
holder.tv = (TextView)convertView.findViewById(R.id.tv_groupName);
}else{
convertView = inflater.inflate(R.layout.item2_layout, null);
holder.tv = (TextView)convertView.findViewById(R.id.tv_teamName);
}
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
TgName tn = tlist.get(position);
holder.tv.setText(tn.getName());
return convertView;
}
class ViewHolder{
TextView tv;
}
}