MyAdapter

package adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.w.lianxi43.MainActivity;
import com.example.w.lianxi43.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import bean.UserBean;

public class ChannelOneAdapter extends BaseAdapter {

    private static final int ITEM_ONT =1;
    private static final int ITEM_TWO =2 ;
    private Context context;
    private List<UserBean.DataBean> list;
    private viewHolder1 holder1;

    public ChannelOneAdapter(Context context, List<UserBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {

        String img = list.get(position).getCdn_img();
        if (img == null) {
            return ITEM_ONT;
        } else {
            return ITEM_TWO;
        }
            
    }

    @Override
    public int getViewTypeCount() {
        return 3;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int type = getItemViewType(position);
        switch (type){
            case ITEM_ONT:
                viewHolder1 holder1=null;
                if (convertView == null) {
                    convertView = View.inflate(context, R.layout.item_layout1, null);
                    holder1 = new viewHolder1();
                    holder1.image = convertView.findViewById(R.id.image_view);
                    holder1.name = convertView.findViewById(R.id.text_name);
                    holder1.type = convertView.findViewById(R.id.text_type);
                    convertView.setTag(holder1);
                } else {
                    holder1= (viewHolder1) convertView.getTag();
                }
                holder1.type.setText(list.get(position).getType());
                holder1.name.setText(list.get(position).getName());
                ImageLoader.getInstance().displayImage(list.get(position).getProfile_image(),holder1.image);
                break;
				
				
				
                case ITEM_TWO:
                    viewHolder2 holder2=null;
                    if (convertView == null) {
                        convertView = View.inflate(context, R.layout.item_layout2, null);
                        holder2 = new viewHolder2();
                        holder2.name = convertView.findViewById(R.id.text_name2);
                        holder2.type = convertView.findViewById(R.id.text_type2);
                        convertView.setTag(holder2);
                    } else {
                        holder2= (viewHolder2) convertView.getTag();
                    }
                    holder2.type.setText(list.get(position).getType());
                    holder2.name.setText(list.get(position).getName());
                    break;

        }
        return convertView;
    }

    class viewHolder{
        TextView type;
        TextView name;
    }
    class viewHolder1 extends viewHolder{
        ImageView image;
    }
    class viewHolder2 extends viewHolder{

    }


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值