Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kodeplay.mytrial
- import android.os.Bundle
- import android.widget.Button
- import androidx.activity.ComponentActivity
- import androidx.activity.compose.setContent
- import androidx.compose.foundation.layout.Column
- import androidx.compose.material.Button
- import androidx.compose.material.MaterialTheme
- import androidx.compose.material.Surface
- import androidx.compose.material.Text
- import androidx.compose.runtime.*
- import androidx.compose.runtime.setValue
- import androidx.compose.runtime.snapshots.SnapshotStateList
- import androidx.compose.ui.tooling.preview.Preview
- import com.kodeplay.mytrial.ui.theme.MytrialTheme
- data class MenuItem (
- val itemName:String ="",
- val itemDesc:String="",
- val itemPrice:Double=0.0,
- val itemPhoto:String="",
- var itemCartQuantity:Int=0,
- var itemIndex:Int=0
- )
- class MainActivity : ComponentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContent {
- var menuItemList = remember { mutableStateListOf <MenuItem>() }
- menuItemList.add(
- MenuItem (
- itemName = "samosa",
- itemDesc = "samosa",
- itemPrice = 10.0,
- itemPhoto = "",
- itemCartQuantity = 0,
- itemIndex=0
- )
- )
- menuItemList.add(
- MenuItem (
- itemName = "vada",
- itemDesc = "samosa",
- itemPrice = 10.0,
- itemPhoto = "",
- itemCartQuantity = 0,
- itemIndex=1
- )
- )
- fun updateCount (index:Int)
- {
- println ("update count called with $index")
- menuItemList[index].itemCartQuantity+=1
- println(menuItemList[index])
- }
- Column {
- for (myItem in menuItemList) {
- Column {
- Text("${myItem.itemName}")
- Text("${myItem.itemCartQuantity}")
- Button(onClick = { updateCount(myItem.itemIndex) }) {
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement