Advertisement
Guest User

Untitled

a guest
May 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package com.example.android.justjava;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.TextView;
  7. import java.text.NumberFormat;
  8. public class MainActivity extends AppCompatActivity {
  9.  
  10. int quantity=0;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. }
  16. /**
  17. * This method is called when the order button is clicked.
  18. */
  19. public void submitOrder(View view) {
  20. display(quantity);
  21. displayPrice(quantity * 5);
  22. }
  23.  
  24. /**
  25. * This method is called when the order button is clicked.
  26. */
  27. public void submitPlus(View view) {
  28. quantity+=1;
  29.  
  30. display(quantity);
  31. }
  32.  
  33. public void submitMinus(View view) {
  34. quantity-=1;
  35. display(quantity);
  36. }
  37.  
  38. /**
  39. * This method displays the given quantity value on the screen.
  40. */
  41. private void display(int number) {
  42. TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
  43. quantityTextView.setText("" + number);
  44. }
  45. /**
  46. * This method displays the given price on the screen.
  47. */
  48. private void displayPrice(int number) {
  49. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  50. priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement