Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make 4 checkboxes for pizza toppings: Ham, Pineapple, Anchovies. and Olives I am struggling to complete this part of the question Also include a button

Make 4 checkboxes for pizza toppings: Ham, Pineapple, Anchovies. and Olives

I am struggling to complete this part of the question "Also include a button which when pressed produces text such as your toppings are Ham and Pineapple in a TextView.".

//XML

xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  app:layout_behavior="@string/appbar_scrolling_view_behavior"  tools:context=".MainActivity"  tools:layout_editor_absoluteY="81dp"  tools:showIn="@layout/activity_main"> <CheckBox  android:id="@+id/ham"  android:layout_width="144dp"  android:layout_height="42dp"  android:layout_marginBottom="14dp"  android:layout_marginStart="16dp"  android:layout_marginTop="16dp"  android:text="Ham"  android:onClick="onClick"  app:layout_constraintBottom_toTopOf="@+id/pineapple"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toTopOf="parent" /> <CheckBox  android:id="@+id/pineapple"  android:layout_width="0dp"  android:layout_height="44dp"  android:layout_marginBottom="14dp"  android:text="Pineapple"  android:onClick="onClick"  app:layout_constraintBottom_toTopOf="@+id/anchovies"  app:layout_constraintEnd_toEndOf="@+id/ham"  app:layout_constraintStart_toStartOf="@+id/ham"  app:layout_constraintTop_toBottomOf="@+id/ham" /> <CheckBox  android:id="@+id/anchovies"  android:layout_width="0dp"  android:layout_height="40dp"  android:layout_marginBottom="12dp"  android:layout_marginEnd="3dp"  android:text="Anchovies"  android:onClick="onClick"  app:layout_constraintBottom_toTopOf="@+id/olives"  app:layout_constraintEnd_toEndOf="@+id/pineapple"  app:layout_constraintStart_toStartOf="@+id/olives"  app:layout_constraintTop_toBottomOf="@+id/pineapple" /> <CheckBox  android:id="@+id/olives"  android:layout_width="139dp"  android:layout_height="41dp"  android:layout_marginBottom="31dp"  android:layout_marginStart="16dp"  android:text="Olives"  android:onClick="onClick"  app:layout_constraintBottom_toTopOf="@+id/textViewContent"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/anchovies" /> <Button  android:id="@+id/button"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_marginBottom="16dp"  android:layout_marginEnd="134dp"  android:layout_marginStart="132dp"  android:text="Click"  android:onClick="onClick"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintEnd_toEndOf="@+id/textViewContent"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/textViewContent" /> <TextView  android:id="@+id/textViewContent"  android:layout_width="0dp"  android:layout_height="0dp"  android:layout_marginBottom="65dp"  android:layout_marginEnd="16dp"  android:layout_marginStart="16dp"  app:layout_constraintBottom_toTopOf="@+id/button"  app:layout_constraintEnd_toEndOf="parent"  app:layout_constraintStart_toStartOf="parent"  app:layout_constraintTop_toBottomOf="@+id/olives" /> android.support.constraint.ConstraintLayout>

//Java

package com.user.qs1; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; import android.view.View.OnClickListener; public class MainActivity extends AppCompatActivity implements View.OnClickListener { CheckBox c1, c2, c3, c4; TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button b = (Button) this.findViewById(R.id.button); textView = (TextView) this.findViewById(R.id.textViewContent); c1 = (CheckBox) this.findViewById(R.id.ham); c2 = (CheckBox) this.findViewById(R.id.pineapple); c3 = (CheckBox) this.findViewById(R.id.anchovies); c4 = (CheckBox) this.findViewById(R.id.olives); b.setOnClickListener(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present.  getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will  // automatically handle clicks on the Home/Up button, so long  // as you specify a parent activity in AndroidManifest.xml.  int id = item.getItemId(); //noinspection SimplifiableIfStatement  if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onClick(View view) { if(c1.isChecked()) { } if(c2.isChecked()) { } if(c3.isChecked()) { } if(c4.isChecked()) { } textView.setText("Your toppings are: " + ); } } 

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

More Books

Students also viewed these Databases questions