Hello. There is a custom array adapter. In getView() highlight the desired Item
if (index == data[position]) convertView.setBackgroundColor(getContext().getResources().getColor(R.color.red)); else convertView.setBackgroundColor(getContext().getResources().getColor(android.R.color.transparent)); But with this approach, if I just click on an item, then selected does not work.
Decided to use setSelected()
if (index == data[position]) convertView.setSelected(true); else convertView.setSelected(false); But item refuses to stand out. Stavil debugging messages with isSelected. So on the item you’ve received, it’s as if it was selected, but visually it’s not.
By event OnItemClickListener
if (index == data[position]) convertView.setSelected(true); else convertView.setSelected(false); Everything stands out. Tell me what could be the problem? Why setSelected() in OnItemClickListener work, but in getView() works, but it doesn't stand out? How to solve it. It is necessary that by clicking on the item a selection flashed and item was highlighted.
getView
public View getView (int position, View convertView, ViewGroup parent) {ViewHolder holder;
if (convertView == null) { convertView = this._layoutInflater.inflate(R.layout.items, parent, false); holder = new ViewHolder(); holder.name = (TextView)convertView.findViewById(R.id.name); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (index == data[position]) { convertView.setBackgroundColor(getContext().getResources().getColor(R.color.red)); //convertView.setSelected(true); } else convertView.setBackgroundColor(getContext().getResources().getColor(android.R.color.transparent)); //convertView.setSelected(false); holder.name.setText(data[position]); return convertView; }