Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am creating an app using Android Studio. We have to have a counter that adds by 1 and subtracts by 1. My code is

I am creating an app using Android Studio. We have to have a counter that adds by 1 and subtracts by 1. My code is below. I included my main-activity and my Counter class. The add count works but when I click the minus button it does not work correctly. I would appreciate any help.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

1 package com.example.pizzaorder; 2 3 Fimport androidx.appcompat.app.AppCompatActivity; 4 5 6 7 import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget. TextView; Aimport android.widget.Toast; 8 9 10 11 4 12 13 public class MainActivity extends AppCompatActivity { Button Place_order, Save_contact; Counter Plus_count; Counter Minus_count; Button btn_tap, btn_tap2; TextView quantity; 14 15 16 17 18 19 OT 20 21 22 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Plus_count = new Counter(); Minus_count = new Counter(); Place_order = findViewById(R.id.Place_button); Save_contact = findViewById(R.id. Save_button); quantity = findViewById(R.id.number_textView); btn_tap2 findViewById(R.id.minus_button); 23 24 25 26 27 = 27 btn_tap2 = findViewById(R.id.minus_button); btn_tap = findViewById(R.id.Plus_button); 28 29 30 31 32 33 of btn_tap.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Plus_count.addCount(); quantity.setText(String.valueOf(Plus_count.getCount())); 34 35 36 37 } 38 39 40 }); 41 42 43 44 of ET btn_tap2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Minus_count.sub Count(); quantity.setText(String.valueof(Minus_count.getCount()); } 45 46 47 48 49 A }); 50 51 } 45 Minus_count.subCount(); quantity.setText(String.valueof(Minus_count.getCount())); 46 47 } 48 49 }); 50 51 } 52 53 @ 54 o public void onClick(View v) { if (v.getId() == Place_order.getId()) { Toast.makeText(getApplicationContext(), text: "1-Begin", Toast.LENGTH_LONG).show(); } 55 56 57 58 == 59 if (v.getId() Save_contact.getId()) { Toast.makeText(getApplicationContext(), text: "2-Exit", Toast.LENGTH_LONG).show(); } 60 61 62 63 } 64 65 } 66 1 ackage com.example.pizzaorder; 2 3 4 public class Counter { private int counter; 5 6 7 8 E public Counter() { this.counter = 0; 9 10 11 } 12 13 public int getCount() { return counter; } 17 18 public void addCount() { counter++; 22 23 public void subCount() { counter--; } 24. 25 public void setCount(int counter) { this.counter = counter; 29 } 30 PizzaOrder Name Cheese 2x Cheese None Square Pizza Circle Pizza Pepperoni Veggies Mushrooms Anchovies 4 PLACE ORDER SAVE ORDER Pizza Order Name Cheese 2x Cheese None Square Pizza Circle Pizza Pepperoni Veggies Mushrooms Anchovies -1 PLACE ORDER SAVE ORDER

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

2. (1 point) Given AABC, tan A b b

Answered: 1 week ago

Question

1. Select the job or jobs to be analyzed.

Answered: 1 week ago