2

I have a problem with "ViewHolder" class. I use "ViewHolder" to improve my List display speech. I think the code is ok, but it throws exception when I am using "setText" with data from "Cursor". Here is my code:

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)));
4

1 回答 1

4

你没有说例外是什么。我猜它是 a NullPointerException,这意味着:

  1. 您的行中没有小部件android:id="@+id/title",或
  2. 您的结果集中没有名为 的列SBooksDbAdapter.KEY_TITLE,或者
  3. 不知何故,您正在创建标签中没有持有人的行
于 2009-08-26T05:10:01.150 回答