繁体   English   中英

当数组中的第n个元素更新时,自定义适配器Android Studio中的第0个元素也会更新。 如何解决这个问题

[英]When nth element in array is updated, 0th element is also updated inside custom adapter Android studio. How to resolve this

数组函数:当我在custom adapter中更新数组中的第n个元素时,它在更新第n个元素时也将第n个值移动到零位置。 例如: Array[0,0,0,2,3,0,0]如果我将第3个位置的值更新为5,则应该为Array[0,0,0,5,3,0,0]但我将成为Array[2,0,0,5,3,0,0] 因此,理想情况是将第n个位置的旧值移动到第0个位置。

知道为什么会这样吗? 下面是示例代码。 当我在“头发”类别中更新时,对于第11或12位的位置超过一次,第0位将更新为先前的值。 但是仅当类别为“美女”时,才应该更新第0位。

 if(categoryPassed == "Beauty"){

  qtyBeauty[position] = qtyBeauty[position] + 1;
}

else if(categoryPassed == "Hair"){

  qtyBeauty[position + 10] = qtyBeauty[position + 10] + 1;
}

问题已解决。 数组在另一个循环中得到更新。 现在找到解决方案。 谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM