Tag: list

Java比较两个列表的对象值?

我有两个列表* *ListA listA = new ArrayList() **和ListB listB = new ArrayList()都包含MyData和MyDatatypes的对象包含这些variables。 MyData { String name; boolean check; } ListA和ListB都包含MyData对象,现在我必须比较列表的对象值这里名称以及检查variables,如果ListA包含这些对象值 ListA = [“Ram”,true],[“Hariom”,true],[“Shiv”,true]; 和ListB也包含 ListB = [“Ram”,true],[“Hariom”,true],[“Shiv”,true]; 那么我必须比较列表,并返回false,因为这两个列表是相同的但是,如果ListA包含 ListA = [“Ram”,true],[“Hariom”,true],[“Shiv”,false]; 和ListB包含 ListB = [“Ram”,true],[“Hariom”,true],[“Shiv”,true]; 那么我必须比较列表并返回true,因为这两个列表不相同 反之亦然,所以任何列表值的任何轻微的变化,我必须返回true。 有一件事我不得不在这里提到对象可以以任何顺序。

当我按ListView项时,请保持突出显示

当我在2 o 3秒内选择一个ListView的元素,然后将手指移动到其他元素并停止按下时,所选的第一个元素始终保持高亮。 我该如何解决这个问题? 谢谢!!! 我忘了说,使用的语言是Kotlin: lvLevels.setOnItemClickListener { adapterView, v, i, l -> Log.i(TAG, "${mapLevels[levelsNameList[i]]}") GlobalStatus.level = mapLevels[levelsNameList[i]] Log.i(TAG, "Prueba level -> ${GlobalStatus.level}") GlobalStatus.levelNumber = i + 1 val intent = Intent(this@LevelsActivity, TheoryActivity::class.java) startActivity(intent) } apdapter: class LevelAdapter(context: Context?, levels: List<String>) : ArrayAdapter<String>(context, R.layout.listitem_levels, levels) { val TAG = javaClass.simpleName val levelsList: List<String> = levels […]

IndexOutOfBoundsException for Kotlin for循环

我有两个相同大小的Kotlin列表, foodObjects: MutableList<ParseObject>? 并checked: MutableList<Boolean>? 。 我需要做一个for循环,每次checked一个元素为true时,从foodObjects获取objectId。 所以这是在Java中: for(int i = 0; i< foodObjects.size(); i++) { //here } 但是在科特林,我不知道为什么,有一些问题。 事实上,如果我这样做: for(i in 0..foodObjects!!.size) { if (checked?.get(i) == true) { objectsId?.add(foodObjects.get(i).objectId) } } 我有IndexOutOfBoundsException :我不知道为什么,它继续在foodObjects.size循环。 我也可以用过滤器和地图来做到这一点: (0..foodObjects!!.size) .filter { checked?.get(it) == true } .forEach { objectsId?.add(foodObjects.get(it).objectId) } 但是我给了同样的错误。 我需要停止使用这个如果: for(i in 0..foodObjects!!.size) { if(i < foodObjects.size) […]