我将微调器的选定项目存储在数组" selectedPayment []"这也存储了很多空值,所以我已将该数组转换为List" payMode"。问题是当我存储元素时,List正在将元素存储在错误的索引中。当我将Array转换为List时会出现问题,因为Array正在以正确的索引存储项目。
例如:我收到[现金,Paypal,礼品卡,Coupans]列表不正确,因为我需要在[Paypal,Coupans,Cash,Gift Card]订单中存储元素。
请告诉我错误的地方。
代码:
public void onItemSelected(AdapterView<?> parent, View v, int position,
long arg3) {
if (parent == spinner_paymentOption) {
selectedPayment[position] = paymentOptionList.get(position);
System.out.println("=====selll "+selectedPayment[position]);
payMode = new ArrayList<String>(Arrays.asList(selectedPayment));
payMode.remove(0);
payMode.removeAll(Collections.singleton(null));
System.out.println("====paymode==="+payMode);
if (!(spinner_paymentOption.getSelectedItemPosition() == 0)) {
isTrue = true;
if (items.contains(position)) {
Toast.makeText(
mActivity,
"You have already selected "
+ selectedPayment[position],
Toast.LENGTH_LONG).show();
} else {
counter++;
createDynamicPaymentLayout(position);
}
}
}
}
答案 0 :(得分:1)
将听众之外的payMode arraylist设为:
payMode = new ArrayList<String>();
并将所选项目添加为:
(您可以在
之后添加以下行selectedPayment[position] = paymentOptionList.get(position); )
payMode.add(paymentOptionList.get(position));
并删除此内容:
payMode = new ArrayList<String>(Arrays.asList(selectedPayment));
payMode.remove(0);
payMode.removeAll(Collections.singleton(null));