简体   繁体   English

Android如何使用while循环更新列表项?

[英]Android how to update list items with a while loop?

I have a list in witch I have only money amounts (numbers), then I want to create a while loop to pull each item in the list (or amount) to be able to do a calculation like adding the tax to the amount and inserting this new amounts to another list in the same order as the original list. 我在巫婆中有一个列表,我只有钱数(数字),然后我想创建一个while循环以拉出列表(或数)中的每个项目,以便能够进行计算,例如向金额中添加税并插入此新内容将以与原始列表相同的顺序成为另一个列表。

this is my code: 这是我的代码:

final ArrayList<Double> individuallist = new ArrayList<Double>();
final ArrayAdapter<Double> bb;
bb = new ArrayAdapter<Double>(this,android.R.layout.simple_list_item_1 ,individuallist);
listView.setAdapter(bb);

//button Next //按钮下一步

    Button next = (Button) findViewById(R.id.btnnext);
    next.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            counter2 = itotal;
            individuallist.add(0, counter2);
            bb.notifyDataSetChanged();
            item1.setText("0");

        }
    });    

the itotal comes from a edit text view itotal来自编辑文本视图

so I have another button where I want to create a click event to do the while loop so I can add tax to every amount place the result in another list in the same order and display it in a second list view, so I don't modify the first list items so I can change the tax rate later and be able to modify the second list every time the second button is press and display the second list updated. 所以我有另一个按钮,我想在其中创建一个单击事件来执行while循环,这样我就可以向每个金额加税,将结果以相同顺序放置在另一个列表中,并在第二个列表视图中显示它,所以我不修改第一个列表项,以便以后可以更改税率,并且每当按下第二个按钮并显示第二个列表更新时,便能够修改第二个列表。

Thanks 谢谢

you can do this easily using for loop like this 您可以像这样使用for循环轻松完成此操作

for(int i=0;i<alist.size();i++)
{

  int amount=alist.get(i);
  int taxadded=//caclutaions on amount;
  anotherlist.add(taxadded);
}

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

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