I have problem with my ListView. I want to set every second element in listView to have its background transparent. I use following code:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row_object, null);
Drawable backgroundDrawable = context.getResources().getDrawable(R.drawable.abstract_gray);
if((int)(position%2)==1)
backgroundDrawable.mutate().setAlpha(ToolsAndConstants.BACKGROUND_TRANSPARENCY);
// It is not working sometimes when I just use v.setBackground(backgroundDrawable); here. Why?
v.setBackground(backgroundDrawable.mutate());
holder = new ViewHolder();
holder.rowNumber = (TextView) v.findViewById(R.id.list_row2_number);
holder.character = (TextView) v.findViewById(R.id.list_row2_char);
holder.strokesNumber = (TextView) v.findViewById(R.id.list_row2_strokes_number);
v.setTag(holder);
}
else
holder = (ViewHolder)v.getTag();
(...)
(...)
(...)
return v;
}
The list loads fine, but the problem is that when I scroll it several times up and down it gets totally crazy (?Randomly? sets transparent background and solid background). Please refer to the screenshots below (before and after scrolling):
Before:
After:
Outside adapter class I just add onClickListener in which I replace fragment with different one. There is no onScrollListener etc. Why the layout is changing?