Note: This has to be done in Kotlin
I want to update the quantity when the user presses the "+" or the "-" button enter image description here
I also want the "0" (Quantity) to be aligned between the two buttons.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="36dp"
android:layout_marginTop="36dp"
android:orientation="vertical"
tools:ignore="HardcodedText">
<TextView
android:id="@+id/Quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="QUANTITY"
android:textSize="23sp" />
<TextView
android:id="@+id/qtr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Quantity"
android:layout_toRightOf="@+id/add"
android:text="@string/Qtr"
android:textSize="23sp" />
<Button
android:id="@+id/orderbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/add"
android:onClick="order"
android:text="Order" />
<Button
android:id="@+id/add"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_below="@+id/Quantity"
android:layout_marginRight="16dp"
android:text="+" />
<Button
android:id="@+id/sub"
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_below="@+id/Quantity"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/qtr"
android:text="-" />
</RelativeLayout>
And this is the Kotlin file code (MainActivity.kt)
package com.example.demoapplicaltion
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Write code here
}
}