我是编程新手,如果您能帮我解决这个问题,那就太好了。我有一个活动,它有一个按钮和一个列表视图。列表视图上的值是名称、价格、类别和数量,并通过适配器定义。我想知道如何将每一行的数量值乘以价格值并将所有这些值相加,并在单击按钮时在吐司中显示结果。这是它的图形,以更好地理解它。这是代码:购物车列表活动.javapublic class CartListActivity extends AppCompatActivity { ListView userList; UserCustomAdapter userAdapter; ArrayList<User> userArray = new ArrayList<User>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cart_list); Button payBtn = (Button)findViewById(R.id.payBtn); payBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), "Total: x€", Toast.LENGTH_SHORT).show(); } }); /** * add item in arraylist */ userArray.add(new User("Olives verdes", "1,20€", "Aperitius", "0")); userArray.add(new User("Olives negres", "1,30€", "Aperitius", "0")); userArray.add(new User("Cogombrets", "1,80€", "Aperitius","0")); userArray.add(new User("Patates Lay's", "1,19€", "Aperitius","0")); userArray.add(new User("Potet", "0,95€", "Bebè","0")); userArray.add(new User("Biberó", "3,85€", "Bebè","0")); userArray.add(new User("Tovalloletes", "1,10€", "Bebè","0")); userArray.add(new User("Perxes de nadó", "1,95€", "Bebè","0")); /** * set item into adapter */ userAdapter = new UserCustomAdapter(CartListActivity.this, R.layout.view_row, userArray); userList = (ListView) findViewById(R.id.listView); userList.setItemsCanFocus(false); userList.setAdapter(userAdapter); /** * get on item click listener */ userList.setOnItemClickListener(new OnItemClickListener()
添加回答
举报
0/150
提交
取消