我正在构建一个自定义列表视图,用于将联系人光标中的联系人列表到一个列表中,其中包含电话号码和联系人姓名的两个文本视图以及图像的位置。当我尝试为我的 TextView 设置文本时出现空点错误即使我检查了变量以查看它们是否包含字符串,但我不知道它有什么问题。
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);
}