如何从适配器中添加从listView中添加到ArrayList的选票项目并发送到活动

发布于 2025-01-30 19:06:44 字数 2042 浏览 3 评论 0原文

对不起,如果我的英语不好。这是我第一次发表问题。我创建一个用于订购的应用程序。我有一个适配器,以ListView的形式显示数据库中的数据。我有一个按钮可以将产品添加到数组中,而添加到数组中的项目仅是已检查的ListView。 我的问题是:

  1. 如何将检查的项目添加到数组中并将其发送到活动中,
  2. 我需要发送3个ID,Quntity和Price

这是我的适配器:

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {

     val inflater = myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as
      LayoutInflater
     val view = inflater.inflate(R.layout.list_product, parent, false)

     val arridProduct= arrayListOf<String>()
     val arrTotalPrice = arrayListOf<String>()
     val arrQuantity = arrayListOf<String>()
     val textNamaProduct = view.findViewById<TextView>(R.id.textViewNamaProduct)
     val textHargaProduct = view.findViewById<TextView>(R.id.textViewHargaProduct)

     var checkBoxAddProduct1 = view.findViewById<CheckBox>(R.id.checkBoxAddProduct)

      =view.findViewById<Button>(R.id.buttonAddToCart)

     var numPickerQuantity1 = view.findViewById<NumberPicker>(R.id.numberPickerQuantity)


      checkBoxAddProduct1.setOnClickListener {


          if(checkBoxAddProduct1.isChecked){

              arridProduct.add(product[position].idProduct)
              arrTotalPrice.add(product[position].price.toString())
              arrQuantity.add(numPickerQuantity1.value.toString())

              numPickerQuantity1.maxValue=10
              numPickerQuantity1.minValue=1

          }
          else{


              arridProduct.remove(product[position].idProduct)
              arrTotalPrice.remove(product[position].price.toString())
              arrQuantity.remove(numPickerQuantity1.value.toString())
              numPickerQuantity1.maxValue=0
              numPickerQuantity1.minValue=0
          }

     }

     textNamaProduct.text=product[position].nama.toString()
     textHargaProduct.text=product[position].price.toString()

     return view
 } }

这是显示“

Sorry if my english is bad. This is my first time post a question. I create an app for ordering. I have a adapter that show data from database in form of listview. I have a button to add product into array and the item that add into array is only listview that has been checked.
My question is:

  1. How to add checked item into array and send it into activity
  2. I need to send 3 data that is id, quntity and price

this is my adapter:

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {

     val inflater = myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as
      LayoutInflater
     val view = inflater.inflate(R.layout.list_product, parent, false)

     val arridProduct= arrayListOf<String>()
     val arrTotalPrice = arrayListOf<String>()
     val arrQuantity = arrayListOf<String>()
     val textNamaProduct = view.findViewById<TextView>(R.id.textViewNamaProduct)
     val textHargaProduct = view.findViewById<TextView>(R.id.textViewHargaProduct)

     var checkBoxAddProduct1 = view.findViewById<CheckBox>(R.id.checkBoxAddProduct)

      =view.findViewById<Button>(R.id.buttonAddToCart)

     var numPickerQuantity1 = view.findViewById<NumberPicker>(R.id.numberPickerQuantity)


      checkBoxAddProduct1.setOnClickListener {


          if(checkBoxAddProduct1.isChecked){

              arridProduct.add(product[position].idProduct)
              arrTotalPrice.add(product[position].price.toString())
              arrQuantity.add(numPickerQuantity1.value.toString())

              numPickerQuantity1.maxValue=10
              numPickerQuantity1.minValue=1

          }
          else{


              arridProduct.remove(product[position].idProduct)
              arrTotalPrice.remove(product[position].price.toString())
              arrQuantity.remove(numPickerQuantity1.value.toString())
              numPickerQuantity1.maxValue=0
              numPickerQuantity1.minValue=0
          }

     }

     textNamaProduct.text=product[position].nama.toString()
     textHargaProduct.text=product[position].price.toString()

     return view
 } }

and this is the example of the display picture

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文