小编And*_*mov的帖子

如何更改ListView上仅选定项目的背景颜色

我正在使用此代码

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parentView, View view, int position, long id) {

            selectid = position;

            for (int j = 0; j < parentView.getChildCount(); j++)
                parentView.getChildAt(j).setBackgroundResource(R.color.listitem_normal);

            // change the background color of the selected element
            view.setBackgroundResource(R.color.listitem_pressed);

        }
    });
Run Code Online (Sandbox Code Playgroud)

但是如果很多项目,如果我选择一个项目并开始向下翻,我看到它被选中,其他项目大约每5个.如果所有项目都放在屏幕上(不需要滚动),一切都OK.

你能解释一下如何解决它吗?我尝试了很多选择.

android listview

1
推荐指数
1
解决办法
556
查看次数

科特林。在嵌套列表中按参数查找元素

我有一些data clases

data class Data(val docNumber: Int?,
            val docType: Int?, 
            val fiscprops: List<FiscProp>, 
            val name: String? 
 ) {

fun getFiscProp(tag: Int) = fiscprops.firstOrNull { it.tag == tag }

}

data class FiscProp(val caption: String?,
                val printable: String?,
                val tag: Int?,
                val value: Any?,
                val fiscprops: List<FiscProp>?) 
Run Code Online (Sandbox Code Playgroud)

我需要FiscProptag嵌套中找到lists。如果我使用,getFiscProp我只能找到FiscProp它是否位于层次结构的第一级。

我怎样才能找到各个级别的元素?不知道会是多少级。

collections kotlin

1
推荐指数
1
解决办法
683
查看次数

标签 统计

android ×1

collections ×1

kotlin ×1

listview ×1