我遇到“ViewHolder”类的问题。我使用“ViewHolder”来改进我的列表显示语音。我认为代码是可以的,但它会抛出异常 我正在使用“setText”和“Cursor”中的数据。这是我的代码:
if(row==null){
LayoutInflater inflater = LayoutInflater.from(context);
row = inflater.inflate(R.layout.sbooks_row, null);
holder = new ViewHolder();
holder.id = (TextView)row.findViewById(R.id.id);
holder.title = (TextView)row.findViewById(R.id.title);
holder.icon = (ImageView)row.findViewById(R.id.icon);
row.setTag(holder);
}
else
{
holder = (ViewHolder)row.getTag();
}
holder.title.setText(cursor.getString(cursor.getColumnIndex(SBooksDbAdapter.KEY_TITLE)));
holder.id.setText(cursor.getString(cursor.getColumnIndex(SBooksDbAdapter.KEY_ROWID)));
答案 0 :(得分:3)
你没有说出异常是什么。我猜它是NullPointerException
,这意味着:
android:id="@+id/title"
或SBooksDbAdapter.KEY_TITLE
或