我正在使用此代码
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.
你能解释一下如何解决它吗?我尝试了很多选择.
我有一些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)
我需要FiscProp在tag嵌套中找到lists。如果我使用,getFiscProp我只能找到FiscProp它是否位于层次结构的第一级。
我怎样才能找到各个级别的元素?不知道会是多少级。