1. 程式人生 > >多條目奇偶數》介面卡-簡易版

多條目奇偶數》介面卡-簡易版

//MainAdapter

package com.example.day09_test01;

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

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class MyloadAdapter extends BaseAdapter {
    private List<String> list;
    private Context context;

    public MyloadAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }


    @Override
    public int getItemViewType(int position) {
        return position%2;
    }

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

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        int type = getItemViewType(position);
        Log.i("TAG",type+"");
        switch (type){
            case 1:
                convertView=View.inflate(context,R.layout.item01,null);
                TextView t1 = convertView.findViewById(R.id.t01);
                t1.setText(getItem(position));
                break;
            case 0:
                convertView = View.inflate(context,R.layout.item02,null);
                TextView t2 = convertView.findViewById(R.id.textView02);
                ImageView imageView = convertView.findViewById(R.id.imageView02);
                t2.setText(list.get(position));
                ImageLoader.getInstance().displayImage("http://f.expoon.com/sub/news/2016/01/21/887844_230x162_0.jpg",imageView);
                break;
        }
        return convertView;
    }

}