Hightlight the ListView row when a contained UI element of row is touched

瘦欲@ 提交于 2019-12-05 07:10:34

问题


I want to enable the orange highlight that occurs when touching a listView row.

If the onclick event was generated from the row itself, I can adjust the hightlight by setting the style of the listview. However in my case, the clicking event is generated by the TextView underneath with onclick event attached to it.

When touch event occurs, Listview isn't aware of clicking is happening. It doesn't receive focused or pressed event.

Is there bubbling or capturing technique I could use like Flex did? Or any suggestion/solution?

Thank you very much.


回答1:


View tempView = null;  // Class Variable to temporary store Clicked Row's view

Method:

 public void onItemClick(AdapterView parent, View v, int position,long id)
{
    listView.setFocusable(true);
    listView.setSelected(true);
    v.setBackgroundColor(Color.LTGRAY); // CHANGE COLOR OF SELECTED ROW HERE>
    selectedId = (int)id;

    if(tempView != null){
        //If row is already clicked then reset its color to default row color
        tempView.setBackgroundColor(Color.TRANSPARENT);

    }
    tempView = v;

}

Hope this helps. Thanks :)



来源:https://stackoverflow.com/questions/4290984/hightlight-the-listview-row-when-a-contained-ui-element-of-row-is-touched

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!