package com.pingyijinren.test; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import java.util.List; /** * Created by Administrator on 2016/5/17 0017. */ public class ListViewArrayAdapter extends ArrayAdapter<String> { private int resourceId; public ListViewArrayAdapter(Context context, int textViewResourceId,List<String> objects){ super(context,textViewResourceId,objects); resourceId=textViewResourceId; } @Override public View getView(int position, View convertView, ViewGroup parent){ String string=getItem(position); View view; ViewHolder viewHolder; if(convertView==null){ view= LayoutInflater.from(getContext()).inflate(resourceId,null); viewHolder=new ViewHolder(); viewHolder.textView=(TextView)view.findViewById(R.id.textView); view.setTag(viewHolder); } else{ view=convertView; viewHolder=(ViewHolder)view.getTag(); } viewHolder.textView.setText(string); return view; } private class ViewHolder{ TextView textView; } }
时间: 2024-11-13 10:31:29