开发者

change listview row background on click

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜