Guest User

Untitled

a guest
Mar 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. package com.example.android.justjava;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.view.View;
  6. import android.widget.TextView;
  7.  
  8. /**
  9. * This app displays an order form to order coffee.
  10. */
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13. int quantity = 2;
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. display(quantity);
  20. }
  21.  
  22. /**
  23. * This method is called when the plus button is clicked.
  24. */
  25. public void increment(View view) {
  26. quantity++;
  27. display(quantity);
  28. }
  29.  
  30. /**
  31. * This method is called when the minus button is clicked.
  32. */
  33. public void decrement(View view) {
  34. if (quantity > 0) quantity--;
  35. display(quantity);
  36. }
  37.  
  38. /**
  39. * This method is called when the order button is clicked.
  40. */
  41. public void submitOrder(View view) {
  42. String priceMessage = "Total: $" + (quantity * 5) + "\nThank you!";
  43. displayMessage(priceMessage);
  44. }
  45.  
  46. /**
  47. * This method displays the given quantity value on the screen.
  48. */
  49. private void display(int number) {
  50. TextView quantityTextView = (TextView) findViewById(
  51. R.id.quantity_text_view);
  52. quantityTextView.setText("" + number);
  53. }
  54.  
  55. /**
  56. * This method displays the given price value on the screen.
  57. */
  58. /*
  59. private void displayPrice(int number) {
  60. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  61. priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
  62. }
  63. */
  64. /**
  65. * This method displays the given text on the screen.
  66. */
  67. private void displayMessage(String message) {
  68. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  69. priceTextView.setText(message);
  70. }
  71.  
  72. }
Add Comment
Please, Sign In to add comment