Search code examples
javaandroidandroid-layoutandroid-listviewandroid-arrayadapter

Highlight items of a listview without using onTouch or onItemClick


I am using a default array adapter to display my listview.

How do I highlight specific rows from my listview without touching anything i.e. without using onTouch() or onItemClick() (Just by using a code!) ?


Solution

  • I guess the way you should do it is use custom adapter and in getVew function highlight the row you needed

    e.g.

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        final Holder holder;
        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
    ... 
    if(position==thePositionYouNeed)
    row.setBackgroundColor(color)