这是我的适配器
public class Vk_row_adapter extends SimpleAdapter {
final String ATTRIBUTE_NAME_TEXT_NAME = "text_name";
final String ATTRIBUTE_NAME_TEXT_PLACE = "text_place";
final String ATTRIBUTE_NAME_IMAGE = "image";
private List<? extends Map<String, ?>> results;
public Vk_row_adapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
this.results = data;
}
public View getView(int position, View view, ViewGroup parent){
View v = view;
TextView tt = (TextView) v.findViewById(R.id.vk_name);
tt.setText((CharSequence) results.get(position).get(ATTRIBUTE_NAME_TEXT_NAME));
TextView bt = (TextView) v.findViewById(R.id.vk_raiting);
tt.setText((CharSequence) results.get(position).get(ATTRIBUTE_NAME_TEXT_PLACE));
ImageView vt = (ImageView)v.findViewById(R.id.vk_photo);
vt.setImageBitmap((android.graphics.Bitmap) results.get(position).get(ATTRIBUTE_NAME_IMAGE));
return v;
}}它给了我一个错误:java.lang.NullPointerException at TextView tt = (TextView) v.findViewById(R.id.vk_name);,哪里是我的错误?我认为错误在创建视图中
发布于 2015-04-05 14:39:13
在使用XML之前,首先需要膨胀XML(XML包含行的布局)。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
...我认为您可以使用ViewHolder模式(安卓文档推荐它)。
请参见:
https://stackoverflow.com/questions/29458293
复制相似问题