0
我正在构建一个自定义列表视图,用于将联系人从联系人光标列出到具有两个文本视图的列表中,以显示联系人的电话号码和姓名以及图像的位置。当我尝试为我的TextView设置文本时,我得到一个空值点错误即使我检查了变量,看他们是否包含一个字符串,我不知道它有什么问题。为CursorAdapter应用自定义列表视图
public View getView(int position, View convertView, ViewGroup parent) {
View rowView=convertView;
ViewCache viewCache=null;
if (rowView==null) {
LayoutInflater inflater=(LayoutInflater)_context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
rowView=inflater.inflate(R.layout.row, null);
viewCache = new ViewCache(rowView);
rowView.setTag(viewCache);
}
else {
viewCache=(ViewCache)rowView.getTag();
}
_cursor.moveToPosition(position);
int id = _cursor.getColumnIndex(People._ID);
int numbercolumn = _cursor.getColumnIndex(People.NUMBER);
int namecolumn = _cursor.getColumnIndex(People.NAME);
String tag = "tag";
Log.i(tag, getItem(position).toString());
String name;
String number;
number = _cursor.getString(numbercolumn);
name = _cursor.getString(namecolumn);
Log.i("test6386", number);
Log.i("Test456", name);
TextView nameView = viewCache.getName();
TextView numberView = viewCache.getNumber();
nameView.setText(name);
numberView.setText(number);
Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, _cursor.getLong(id));
Bitmap bitmap = People.loadContactPhoto(_context, uri, R.drawable.icon, null);
viewCache.getIcon().setImageBitmap(bitmap);
return(rowView);
}
请包括堆栈跟踪 – I82Much 2009-11-02 13:40:48