Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Need Help

  1. #1
    New to the CF scene
    Join Date
    Mar 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help

    Im a full time student in high school an im having problems with one of my assignments in android studio. in our class we are suppose to create a lunch app in xml. i got the basics already there but on my fries section when i click the + sign on my phone for testing it changes the number for the burger + button instead of changing the fries number it changes the burger number i need help with my class an imma come here alot for help this class is too hard for me.


    The XML Part

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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="com.google.example.lunchapp.MainActivity">
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relativeLayout2"
            android:layout_marginTop="21dp"
            android:layout_toLeftOf="@+id/button3"
            android:layout_toStartOf="@+id/button3"
            android:text="Burgers"
            android:textAllCaps="true" />
    
        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:orientation="horizontal"
            android:paddingLeft="8dp"
            android:paddingRight="8dp">
    
    
        </RelativeLayout>
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="26dp"
            android:layout_marginLeft="14dp"
            android:layout_marginStart="14dp"
            android:text="Total"
            android:textAllCaps="true" />
    
        <TextView
            android:id="@+id/price_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button2"
            android:layout_alignLeft="@+id/textView"
            android:layout_alignStart="@+id/textView"
            android:text="$0"
            android:textColor="@android:color/black"
            android:textSize="16sp" />
    
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="23dp"
            android:onClick="submitOrder"
            android:text="Order" />
    
        <Button
            android:id="@+id/button"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignBaseline="@+id/button3"
            android:layout_alignBottom="@+id/button3"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:onClick="decrement"
            android:text="-" />
    
        <Button
            android:id="@+id/button3"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_below="@+id/textView2"
            android:layout_marginTop="19dp"
            android:layout_toEndOf="@+id/button2"
            android:layout_toRightOf="@+id/button2"
            android:onClick="increment"
            android:text="+" />
    
        <TextView
            android:id="@+id/quantity_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button"
            android:layout_alignBottom="@+id/button"
            android:layout_toEndOf="@+id/textView"
            android:layout_toRightOf="@+id/textView"
            android:text="2"
            android:textColor="@android:color/black"
            android:textSize="16sp" />
    
        <RelativeLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/relativeLayout2" />
    
    
        <Button
            android:id="@+id/button4"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/button"
            android:layout_marginTop="51dp"
            android:onClick="decrement2"
            android:text="-" />
    
        <Button
            android:id="@+id/button5"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignBaseline="@+id/button4"
            android:layout_alignBottom="@+id/button4"
            android:layout_alignLeft="@+id/button3"
            android:layout_alignStart="@+id/button3"
            android:onClick="increment2"
            android:text="+" />
    
        <TextView
            android:id="@+id/FRIES"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button5"
            android:layout_toEndOf="@+id/button4"
            android:layout_toRightOf="@+id/button4"
            android:text="FRIES" />
    
        <TextView
            android:id="@+id/quantity_text_view2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button5"
            android:layout_alignBottom="@+id/button5"
            android:layout_toEndOf="@+id/quantity_text_view"
            android:layout_toRightOf="@+id/quantity_text_view"
            android:text="2"
            android:textColor="@android:color/black"
            android:textSize="16sp"
            />
    
    </RelativeLayout>
    The Java Part

    Code:
    package com.google.example.lunchapp;
    
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.TextView;
    
    import com.google.example.lunchapp.R;
    
    import java.text.NumberFormat;
    
    
    /**
     * This app displays an order form to order coffee.
     */
    public class MainActivity extends AppCompatActivity {
    
        int quantity = 2;
    
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        public void increment(View view) {
            quantity = quantity + 1;
            display(quantity);
        }
    
        private void displayMessage(String message) {
            TextView priceTextView = findViewById(R.id.price_text_view);
            priceTextView.setText(message);
        }
    
        public void decrement(View view) {
            quantity = quantity - 1;
            display(quantity);
        }
    
        /**
         * This method is called when the order button is clicked.
         */
        public void submitOrder(View view) {
            int price = (quantity * 5);
            String priceMessage = "Total: $" + price;
            priceMessage = priceMessage + "\nThank you!";
            displayMessage(priceMessage);
        }
    
    
    
    
    
        /**
         * This method displays the given quantity value on the screen.
         */
        private void display(int number) {
            TextView quantityTextView = findViewById(R.id.quantity_text_view);
            quantityTextView.setText("" + number);
        }
    
    
    
    
        private void displayPrice(int number) {
            TextView priceTextView = findViewById(R.id.price_text_view);
            priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
        }
    
    
    
    
        public void increment2(View view) {
            quantity = quantity + 1;
            display(quantity);
        }
    
        public void decrement2(View view) {
            quantity = quantity - 1;
            display(quantity);
        }
    }
    What my app looks like!

    ibb.co/e8j57n

    if anyone can help me with this project that be awesome been stuck on this for days

  2. #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,511
    Thanks
    1
    Thanked 24 Times in 22 Posts
    Generally speaking, we do not answer student homework problems... in this case I know I cannot help you anyway because I don't know Java and I definitely don't know any GUI programming in Java or Android.

    Maybe someone else familiar with those API's can point you in the right direction. Have you considered privately approaching your instructor?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, ES-Membrane project (Github Pages site)
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •