ここでアンドロイドを初めて使用します。カーソル アダプターについて質問がありました。だからここに私のコードがあります:カーソルアダプタークラスには、これらのメソッドがあります:
public void bindView(final View view, final Context context, final Cursor cursor) {
stuff....
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return stuff...
}
同じものを探しているときにオンラインで見つけたものに基づいて getview メソッドを追加しようとしました。これは次のとおりです。
public View getView(int position, View convertView, ViewGroup parent) {
if (!mDataValid) {
throw new IllegalStateException("this should only be called when the cursor is valid");
}
if (!mCursor.moveToPosition(position)) {
throw new IllegalStateException("couldn't move cursor to position " + position);
}
View v;
if (convertView == null) {
v = newView(mContext, mCursor, parent);
} else {
v = convertView;
}
/*if (position % 2 == 0){
convertView.setBackgroundResource(R.drawable.orangecellcolor);
} else {
convertView.setBackgroundResource(R.drawable.greencellcolor);
}*/
bindView(v, mContext, mCursor);
return v;
}
間にコメントされているコード ブロックは、代替セルのコードです。コメントを外すたびに、エラーや警告は表示されませんが、クラッシュします。さて、コードを getview で上書きする方法を知る必要があります。言及したメソッドのいくつかを削除する必要がありますか、それともカーソル アダプター クラスに何か問題がありますか? 誰かが上記のコードを修正/修正したり、同じ修正方法を教えてくれたりできますか? ありがとう!ジャスティン