Hightlight ListView中行时行的包含的UI元素被感动时行、中行、元素、Hightlight

2023-09-05 11:22:12 作者:笑拥孤独

我要启用触摸一个ListView一行时出现橙色亮点。

如果从该行本身所产生的onclick事件,我可以通过设置列表视图的风格调整hightlight。然而,在我的情况下,点击事件被TextView中产生的下方与连接到其onclick事件。

当触摸事件发生时,列表视图不知道点击的发生。它不接收集中或pressed事件。

时有气泡或捕获技术,我可以使用类似的Flex那样?或任何建议/解决方案?

非常感谢你。

解决方案

 查看tempView = NULL; //类变来临时存储已点击行的观点
 
10张界面细节元素UI

方法:

 公共无效onItemClick(适配器视图父,视图V,INT位置,长ID)
{
    listView.setFocusable(真正的);
    listView.setSelected(真正的);
    v.setBackgroundColor(Color.LTGRAY); //改变选择的行这里制造&gt颜色;
    selectedId =(INT)ID;

    如果(tempView!= NULL){
        //如果行已经单击了那么重的颜色为默认的行颜色
        tempView.setBackgroundColor(Color.TRANSPARENT);

    }
    tempView = V;
 

}

希望这有助于。感谢:)

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.

解决方案

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 :)