My Trial With Coffee Ordering App

<?xml version="2.0" encoding="utf-8"?><LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"
    tools:context=".MainActivity">

    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingRight="5dp" >

        <ImageView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:src="@drawable/images"            android:scaleType="centerCrop"            andr            android:layout_gravity="top"            />
      <android.support.v7.widget.LinearLayoutCompat          android:layout_width="match_parent"          android:layout_height="match_parent"          android:orientation="vertical">
          <TextView              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_margin="16dp"              android:text="quantity"              android:textAllCaps="true"/>

          <Button              android:id="@+id/button3"              android:layout_width="48dp"              android:layout_height="48dp"              android:onClick="increment"              android:layout_marginBottom="16dp"              android:layout_marginLeft="16dp"              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="16dp"              android:text="0"              android:textColor="#000000"              android:textSize="16sp"/>

          <Button              android:id="@+id/button4"              android:layout_width="48dp"              android:layout_height="48dp"              android:onClick="decrement"              android:layout_marginLeft="16dp"              android:text="-" />

          <TextView              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_marginStart="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_marginLeft="16dp"              android:layout_marginTop="16dp"              android:text="$0"              android:textColor="#000000"              android:textSize="16sp"/>

          <Button              android:id="@+id/button"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_marginLeft="16dp"              android:layout_marginTop="16dp"              android:onClick="submitOrder"              android:text="order"              android:textAllCaps="true"/>

      </android.support.v7.widget.LinearLayoutCompat>
        

    </RelativeLayout>
    
</LinearLayout>


JAVA CODE

 package com.example.android.justjava;

/** * IMPORTANT: Add your package below. Package name can be found in the project's AndroidManifest.xml file. * This is the package name our example uses: * <p>
 * package com.example.android.justjava; */

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.text.NumberFormat;

/** * This app displays an order form to order coffee. */public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**     * This method is called when the plus button is clicked.     */    public void increment(View view) {
        int quantity = 2;
            quantity = quantity + 1;
            display(quantity);

/** * This method is called when the minus button is clicked. */    }
    public void decrement(View view) {
        int quantity = 2;
            quantity = quantity - 1;
            display(quantity);



    }
    public void submitOrder(View view) {
        int quantity = 5;
        display(quantity);
        displayPrice(quantity * 5);
    }

    /**     * This method displays the given price on the screen.     */    private void displayPrice(int number) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
        priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
    }

    /**     * 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);
    }
}

Comments

Popular posts from this blog

Choose Your Social Media Channels Week 5 Quiz