开发者

change listview row background on click

开发者 https://www.devze.com 2023-03-30 04:45 出处:网络
I need to change background color of a row in a listview when it\'s clicked by the finger. Example: I\'ve got as listview with 5/6 rows; I need that with a single click on one row its background color

I need to change background color of a row in a listview when it's clicked by the finger. Example: I've got as listview with 5/6 rows; I need that with a single click on one row its background color becomes green (selected). W开发者_高级运维ith an other click on the selected row the background becames black again.

How can I do that?

Thank you


public View getView(final int position, View convertView,ViewGroup parent) {
        ViewHolder holder;  

        if (convertView == null)
        {   
           convertView.setTag(holder);  
        }       
        else {
                 holder = (ViewHolder) convertView.getTag();
        }   
        if(position == your selected row position)
        {
          convertView.setBackgroundColor(Color.YELLOW);
        }

        return convertView;

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消