在可扩展的ListView的Andr​​oid点击过的儿童更改背景颜色 [英] Change Background Color of Clicked Child in Expandable ListView Android

查看:137
本文介绍了在可扩展的ListView的Andr​​oid点击过的儿童更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变该被点击以ExpandableListView儿童的背景颜色。
也就是说,任何一个孩子点击时,它的背景颜色应该得到改变。
我试图去它以这种方式,但它选择一些其他的行,而不是已被点击的人。

I want to change the background color of the child which is clicked in an ExpandableListView. That is, when any child is clicked, it's background color should get changed. I am trying to go it in this way but it selects some other row, not the one which has been clicked.

public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {

    parent.getChildAt(childPosition).setBackgroundColor(Color.DKGRAY);

    return false;
}

请告诉我,我可能会丢失。

Please tell me what I might be missing.

推荐答案

如何让说你想直接引用您的看法,并设置这样的背景下,

How about lets say you try to directly refer your view and set the background like this,

public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {

         v.setBackgroundColor(Color.BLUE);

    return false;
}

这篇关于在可扩展的ListView的Andr​​oid点击过的儿童更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆