input
xml code
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/activity_main"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.saketh.firstprojectman.MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:text="quantity"
- android:textAllCaps="true" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:layout_width="48dp"
- android:layout_height="48dp"
- android:onClick="decrement"
- android:text="-" />
- <TextView
- android:id="@+id/quantity_text_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:layout_marginLeft="8dp"
- android:text="0"
- android:textAllCaps="true"
- android:textColor="@android:color/black"
- android:textSize="16sp"
- android:paddingLeft="8dp"
- android:paddingRight="8dp"/>
- <Button
- android:layout_width="48dp"
- android:layout_height="48dp"
- android:layout_marginLeft="8dp"
- android:onClick="increment"
- android:text="+" />
- </LinearLayout>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:layout_marginTop="16dp"
- android:text="price"
- android:textAllCaps="true" />
- <TextView
- android:id="@+id/price_text_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:text="0"
- android:textAllCaps="true"
- android:textColor="@android:color/black"
- android:textSize="16sp" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:onClick="submitOrder"
- android:text="order" />
- </LinearLayout>
java code} }
- package com.example.saketh.firstprojectman; /**
- * Add your package below. Package name can be found in the project's AndroidManifest.xml file.
- * This is the package name our example uses:
- *
- * package com.example.android.justjava;
- */
- import android.icu.text.NumberFormat;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.TextView;
- import com.example.saketh.firstprojectman.R;
- import static android.icu.text.NumberFormat.getCurrencyInstance;
- /**
- * This app displays an order form to order coffee.
- */
- public class MainActivity extends AppCompatActivity {
- int quantity=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- /**
- * This method is called when the order button is clicked.
- */
- public void submitOrder(View view) {
- int numberOfCoffee=quantity;
- display(numberOfCoffee);
- priceBox(numberOfCoffee*2);
- }
- /**
- * This method displays the given quantity value on the screen.
- */
- private void display(int number) {
- TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
- quantityTextView.setText("" + number);
- }
- private void priceBox(int number){
- TextView pricetext=(TextView) findViewById(R.id.price_text_view);
- pricetext.setText(NumberFormat.getCurrencyInstance().format(number));
- }
- public void increment(View view){
- quantity=quantity+1;
- display(quantity);
- }
- public void decrement(View view){
- quantity=quantity-1;
- display(quantity);
output


No comments:
Post a Comment