如何从适配器中添加从listView中添加到ArrayList的选票项目并发送到活动
对不起,如果我的英语不好。这是我第一次发表问题。我创建一个用于订购的应用程序。我有一个适配器,以ListView的形式显示数据库中的数据。我有一个按钮可以将产品添加到数组中,而添加到数组中的项目仅是已检查的ListView。 我的问题是:
- 如何将检查的项目添加到数组中并将其发送到活动中,
- 我需要发送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:
- How to add checked item into array and send it into activity
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论