問題"ViewHolder"クラススケーラビリティ
-
19-09-2019 - |
質問
していま問題"ViewHolder"クラスです。を用いてViewHolder"の向上で一覧表示。私のコードはokですが、例外をスローしき を使って"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)));
解決
ただ何と言っても、例外です。いいです NullPointerException
, は、次のいずれかに
- お持ちでないウィジェットに行
android:id="@+id/title"
, や - いないカラムに結果セットの名前
SBooksDbAdapter.KEY_TITLE
, や - なんだかんを行ないホルダーにタグ
所属していません StackOverflow