android程序员通...吧 关注:19贴子:308
  • 2回复贴,共1

你们这些人

只看楼主收藏回复

看来是时候展示本大人的能力了


1楼2015-09-25 09:39回复
    挽尊


    IP属地:北京4楼2015-09-25 09:43
    回复
      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;
      }
      }


      5楼2015-11-01 20:19
      回复