Question: Make 4 checkboxes for colors: pink red blue orange Also include a button which when pressed produces text such as your colors are pink and

Make 4 checkboxes for colors: pink red blue orange

Also include a button which when pressed produces text such as your colors are pink and red in a TextView.

I have already declared the variables and have written the basic outline of the checkbox function...just need help with connecting the checkboxes with the button/textview.

public class MainActivity extends AppCompatActivity implements 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 = (TextView)this.findViewById(R.id.textView); c1 = (CheckBox)this.findViewById(R.id.pink); c2 = (CheckBox)this.findViewById(R.id.red); c3 = (CheckBox)this.findViewById(R.id.blue); c4 = (CheckBox)this.findViewById(R.id.orange); 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); } public void onClick(View view) { //Is the view now checked?  boolean checked = ((CheckBox)view).isChecked(); //Check which checkbox was clicked  switch(view.getId()) { case R.id.pink: if (checked) //  else  //  break; case R.id.red: if (checked) //  else  //  break; case R.id.blue: if (checked) //  else  //  break; case R.id.orange: if (checked) //  else  //  break; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!