我正在尝试像这样覆盖 getview 方法:
public class MyArrayAdapter extends ArrayAdapter {
private final Context context;
private final ArrayList<DataList> values;
private final LayoutInflater li = LayoutInflater.from(this.getContext());
public MyArrayAdapter(Context context, int textViewResourceId,ArrayList<DataList> values) {
super(context,textViewResourceId, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
convertView=li.inflate(R.layout.simplerow,parent,false);
holder=new ViewHolder();
holder.text=(TextView) convertView.findViewById(R.layout.simplerow);
convertView.setTag(holder);
}else{
Log.d("a","entre else");
holder=(ViewHolder)convertView.getTag();
}
DataList b=values.get(1);
String c=b.toString();
holder.text.setText(values.get(position).toString());
try {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return convertView;
}
static class ViewHolder {
TextView text;
}
每次我到达 holder.text.setText(values.get(position).toString())
我都会收到null pointer exception
错误。VALUES 是arraylist
DataList 类型,Datalist 是我的类,它返回两个字符串。我知道 Values 不为空。