Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5953067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:46:18+00:00 2026-05-22T17:46:18+00:00

I am attempting to make it so that whenever a checkbox is checked the

  • 0

I am attempting to make it so that whenever a checkbox is checked the view is one color and when it is unchecked it is another however when i check the box the view turns black and then nothing else happens when i check or uncheck the box.

activity:

package fsg.dev.test.checkboxtest;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.view.View.OnClickListener;
import android.widget.SeekBar;

public class checkBoxTest extends Activity implements OnClickListener {
CheckBox checkbox;
SeekBar seekbar;
View view;
Button button;

private static final String TAG = "Checkbox Test";

@Override
public void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    checkbox = (CheckBox) findViewById(R.id.checkbox);
    seekbar = (SeekBar) findViewById(R.id.seekbar);
    view = (View) findViewById(R.id.background);
    button = (Button) findViewById(R.id.button);

    button.setOnClickListener(this);
    checkbox.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            final String bool;
            if(((CheckBox) v).isChecked()){
                bool = "True";
                Log.d(TAG, bool);
                setBlue();
            } else {
                bool = "False";
                Log.d(TAG, bool);
                setDefault();
            }
        }
    });
}

@Override
public void onClick(View v){
    checkbox.toggle();
    view.setBackgroundColor(R.color.Color);
}

private void setBlue(){
    Log.d(TAG, "In setBlue()");
    view.setBackgroundColor(R.color.Color);
}

private void setDefault(){
    Log.d(TAG, "In setDefault()");
    view.setBackgroundColor(R.color.Default);
}
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox 
    android:text="Background Color" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:checked="false"
    android:id="@+id/checkbox">
</CheckBox>
<Button
    android:text="Background Color" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button">
</Button>
<SeekBar 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:id="@+id/seekbar" 
    android:layout_margin="10dip" >
</SeekBar>
<View
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/Default"
    android:id="@+id/background">
</View>

manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="fsg.dev.test.checkboxtest"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:name=".checkBoxTest"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

can anyone figure out what i’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:46:19+00:00Added an answer on May 22, 2026 at 5:46 pm

    change the method setBlue() and setDefault() , with :
    YourActivity.this.setBlue() and YourActivity.this.setDefault();

    Note : in the view.setBackgroundColor(R.color.yourColor) ; replace it with : view.setBackgroundColor(Color.BLUE) ;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a custom ContentProvider so that more than one application (activity?)
I am attempting to make a check that once clicked will check all the
Attempting to make a NSObject called 'Person' that will hold the login details for
I am attempting to make a program that will pull data such as OS,
I am attempting to make a class that has a template object member inside
Im attempting to make a little app that lets you add text boxes to
I'm attempting to make a table that has header rows that can be collapsed
I am attempting to make it so that we can have our application to
I'm attempting to make a class that holds a (in theory) infinite amount of
I'm attempting to make a system that stores employees details...name address etc. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.