package com.example.myapplication; 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.List; public class MListAdapter extends BaseAdapter { List<costList> mList; public MListAdapter(List<costList>list) { mList=list; } @Override public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view=mLayoutInflater.inflate(R.layout.list_month,null); //取出数据赋值 costList item=mList.get(position); TextView month=view.findViewById(R.id.month); //绑定 month.setText(mList.get(position).getDate().substring(0,4)); return view; } private List<costList>getmList; private LayoutInflater mLayoutInflater; public MListAdapter(Context context, List<costList>list) { mList=list; //通过外部传来的Context初始化LayoutInflater对象 mLayoutInflater=LayoutInflater.from(context); } }标签:mList,position,import,android,2.14,public,view From: https://www.cnblogs.com/luoqingci/p/18040467