문제

"Viewholder"클래스에 문제가 있습니다. "Viewholder"를 사용하여 목록 디스플레이 음성을 개선합니다. 코드는 괜찮다고 생각하지만 "Cursor"의 데이터와 함께 "settext"를 사용할 때 예외가 발생합니다. 내 코드는 다음과 같습니다.

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)));
도움이 되었습니까?

해결책

당신은 예외가 무엇인지 말하지 않습니다. 나는 그것이 A라고 추측 할 것이다 NullPointerException, 이는 다음 중 하나를 의미합니다.

  1. 당신은 당신의 행에 위젯이 없습니다. android:id="@+id/title", 또는
  2. 결과 세트에 이름이없는 열이 없습니다. SBooksDbAdapter.KEY_TITLE, 또는
  3. 어떻게 든 태그에 홀더가없는 행을 생성하고 있습니다.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top