1行おきに異なる色を取得しようとしています
スクロールが速すぎると、3つの白い行が連続して表示される可能性があります(しゃれは意図されていません笑)
public class TestAdapter extends ArrayAdapter<Enlevement> {
private final Activity context;
private boolean shouldCreateGreyBackground = false;
static class ViewHolder {
public TextView text;
public LinearLayout layout;
}
public TestAdapter(Activity context ) {
super(context, 0);
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView;
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.list_item_enlevement_grey, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.enlevementDate);
viewHolder.layout = (LinearLayout) rowView.findViewById(R.id.layoutEnlevementItemGrey);
rowView.setTag(viewHolder);
ViewHolder holder = (ViewHolder) rowView.getTag();
Enlevement entry = getItem(position);
holder.text.setText(String.valueOf(entry.i));
if(shouldCreateGreyBackground){
holder.layout.setBackgroundResource(R.drawable.selector_listview_grey);
shouldCreateGreyBackground = false;
}
else{
holder.layout.setBackgroundResource(R.drawable.selector_listview_white);
shouldCreateGreyBackground = true;
}
return rowView;
}
}
私は運が悪かったこのbtへのいくつかの修正とアプローチを試みました。何か案は?