ListAdapter适配器

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


import java.util.ArrayList;


/**
 * Created by lvxinxin on 2018/1/22.
 */


public class MyAdapter extends BaseAdapter {


    private ArrayList mList;
    private Context mContext;


    public MyAdapter(ArrayList mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }


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


    @Override
    public Object getItem(int position) {
        return null;
    }


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


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);
            holder.mText = convertView.findViewById(R.id.ListView_Name);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.mText.setText(mList.get(position));
        return convertView;
    }




    class Holder {
        private TextView mText;
    }
}

你可能感兴趣的:(安卓,模板)