Ad
How To Access Arraylist Data In Kotlin
i have:
var itemOrder = ArrayList<String>()
file model Order.kt:
private var itemName:String? = null
private var note:String? = null
private var price: CharSequence? = null
private var all: Int? = null
private var quantity: Int? = null
fun Order(itemName: String, price: CharSequence, all: Int, note: String, quantity: Int)
{
this.itemName = itemName
this.price = price
this.all = all
this.note = note
this.quantity = quantity
}
then i add for itemOrder like this:
itemOrder.add(Order.Order(finalHolder1.nameItem!!.text.toString(),`finalHolder1 priceItem!!.text, finalHolder1.quantity, finalHolder1.note!!.text.toString(), finalHolder1.quantity * hargaSatuan).toString())
then
fun cart(): ArrayList<String> {
return itemOrder
}
i want to see all item value where i have add before to itemOrder in Toast like
itemName : valueofValue
price: valueofprice
all: valueofall
note: valueofnote
quantity: valueofquantity
Toast.makeText(applicationContext, "List Item : "+ cart(), Toast.LENGTH_LONG).show()
but i get this result: Result
i want change result of kotlin.init to value each array in array
Ad
Answer
Instead of primitive String type , arraylist should be "Order" of type;
var itemOrder = ArrayList<Order>()
Instead of how you defined the model class, define as
data class Order(
val itemName:String,
val note:String,
val price: CharSequence,
val all: Int,
val quantity: Int
);
// add item as
itemOrder.add(Order(finalHolder1.nameItem!!.text.toString(),`finalHolder1 priceItem!!.text, finalHolder1.quantity, finalHolder1.note!!.text.toString(), finalHolder1.quantity * hargaSatuan).toString())
// print each value as
fun( 0 in until itemOrder.size){
Log.e("name",itemOrder[i].itemName);
//get all data in the same way
}
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad