私のテーブルのフィールドの値(trueまたはfalse)に応じて、私のリストに1つのカスタマイズされたレイアウトを持つCursorAdapterを使用すると、リストアイテム内のtextviewの1つの色が異なります。CursorAdapter - List beheivour
public class CustomAdapter extends CursorAdapter {
DatabaseHelper myDB;
SQLiteDatabase db;
public CustomAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, 0);
myDB = new DatabaseHelper(context, DatabaseHelper.DB_NAME, null, DatabaseHelper.DB_VERSION_SCHEME);
db = myDB.getReadableDatabase();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.customize_cell_list, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tv = (TextView) view.findViewById(R.id.tv);
TextView tv_date = (TextView) view.findViewById(R.id.tvDateCursor);
TextView tv_time = (TextView) view.findViewById(R.id.tvTime);
ImageView img = (ImageView)view.findViewById(R.id.img);
if(cursor != null) {
String tv = cursor.getString(2);
String date = cursor.getString(3);
String time = cursor.getString(8);
boolean active = cursor.getInt(12) > 0;
boolean go = cursor.getInt(13) > 0;
tv_date.setText(date);
tv.setText(tv);
if(go) { // OPTION 1
img.setImageResource(R.drawable.calle);
tv_time.setText(time);
} else { // OPTION 2
img.setImageResource(R.drawable.casa);
if(active){ // OPTION 2.1
tv_time.setText("Activado");
}else{ // OPTION 2.2
tv_time.setText("No activado");
tv_time.setTextColor(Color.RED);
}
}
}
}
}
結果:私はOPTION 2.2で一つのアイテムを持っていると私のtv_timeの一部ダウン(偶数からとスクロールアップ起動したときの画像が、問題は色で、textviewsと同じ正しいものを表示しますオプション1)色を赤に変え始めたら、もう一度スクロールして白くなり、他は赤に変わります。これはランダムなものです。
どうしてですか? "go"と "active"が間違っている場合にのみ、赤い色をどのように保つことができますか?あなたはリストビューで 1.ビューが限られている次の事を覚えておく必要が
おかげ
ありがとう、私は私の質問を削除します。 – lulu666
常にViewHolderを使用してください。 findViewById()はスクロール中にフリッカー効果をもたらす高価なタスクです –