У меня есть listView, и я хочу поместить выделение с градиентом цвета в качестве фона. Это выглядит следующим образом:Динамически изменяемый градиент цвета в адаптере
Как вы можете видеть, что это работает благодаря этому ответу:
How to change color of drawable shapes in android, но я не знаю, почему мой первый элемент взять прозрачный фон и его цвет берется для следующего пункта.
Вот мой адаптер код:
public class PromoAdapter extends ArrayAdapter {
private Context context;
private ArrayList<PromoObject> originalData = null;
private GradientDrawable gradient;
public PromoAdapter(Context context, ArrayList<PromoObject> listArray) {
super(context, R.layout.home_promo_item);
this.context = context;
this.originalData = listArray ;
}
public static class Row
{
public RelativeLayout layout;
public TextView labelPromo;
}
@Override
public int getCount() {
return originalData.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// reuse views
if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(context);
rowView = inflater.inflate(R.layout.home_promo_item, null);
// configure view holder
Row viewHolder = new Row();
viewHolder.labelPromo = (TextView) rowView.findViewById(R.id.label_promo);
rowView.setTag(viewHolder);
}
Row holder = (Row) rowView.getTag();
PromoObject itm = originalData.get(position);
holder.labelPromo.setText(itm.getPromoValue());
rowView.setBackgroundDrawable(gradient);
gradient = new GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT,
new int[] {0xFF616261,0xFF131313});
gradient.setCornerRadius(15f);
return rowView;
}
}
код или не бывает. – Simas
Почтовый код адаптера. –
готов код =) @Simas –