The app is a Food Ordering App. I have added only few dishes from many in an array using intent.After I click proceed to cart button how can i see my dishes in another activity that are only added.
This is the code where i take the added dishes in array.
val desc = dishList[position]
holder.txtDishName.text = desc.desName
holder.txtCost_for_one.text = desc.desCost_for_one
holder.btnAdd.setOnClickListener {
if (holder.btnAdd.text == "ADD") {
val obj = Cart(
desc.id,
desc.desName,
desc.desCost_for_one,
desc.restaurant_id
)
addToCart.add(obj)
holder.btnAdd.text = "Remove"
val favColor = ContextCompat.getColor(this.context, R.color.colorPrimary)
holder.btnAdd.setBackgroundColor(favColor)
} else{
for (i in 0 until addToCart.size ){
if (addToCart[i].cId == desc.id){
addToCart.removeAt(i)
}
}
holder.btnAdd.text = "Add"
val favColor = ContextCompat.getColor(this.context, R.color.colorAccent)
holder.btnAdd.setBackgroundColor(favColor)
}
val intent = Intent(context, DescriptionActivity::class.java)
intent.putExtra("addToCart",addToCart)
}
}
This is the code where i click on the proceed to cart button.
btnProceed.setOnClickListener {
val intent = Intent(this, CartActivity::class.java)
//intent.getStringArrayExtra("addToCart")
intent.getStringExtra("addToCart")
startActivity(intent)
But after running the app the CartActivity comes Empty.