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 8304893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:57:33+00:00 2026-06-08T17:57:33+00:00

The issue I am having is managing the states of a togglebutton being on

  • 0

The issue I am having is managing the states of a togglebutton being on and off. The button turns bluetooth on/off. How can I make it so the button can be toggled readily on and off without closing the app? Right now it only works when launching the application.

if(!myBluetooth.isEnabled()){

            final ToggleButton tglbtn = (ToggleButton)findViewById(R.id.ToggleButton01);

            tglbtn.setChecked(false);
           tglbtn.setOnClickListener(new OnClickListener(){
                 public void onClick(View v) {
                    myBluetooth.enable();}});

            }

        else {
            ToggleButton tglbtn = (ToggleButton)findViewById(R.id.ToggleButton01);

            tglbtn.setChecked(true);

          tglbtn.setOnClickListener(new OnClickListener(){
           public void onClick(View v) {
            myBluetooth.disable();}});
        }

I tried implementing a loop to accomplish this, but the app kept crashing, the only other thing I could think of is a goto down at the bottom below the two myBluetooth instance’s, linking to the other one but since that’s not possible in java, I’m out of ideas.

while(myBluetooth != null){
             tglbtn.setOnClickListener(new OnClickListener(){
                 public void onClick(View v) {
                    myBluetooth.enable();
                    toggleflag = true; }});
                    while (toggleflag){
                        tglbtn.setOnClickListener(new OnClickListener(){
                            public void onClick(View v) {
                                myBluetooth.disable();
                                toggleflag = false; }});

                    }

            }
  • 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-06-08T17:57:35+00:00Added an answer on June 8, 2026 at 5:57 pm

    Try This

    ToggleButton toggle = (ToggleButton) findViewById(R.id.toggle);
    toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    Toast.makeText(getApplicationContext(), buttonView.isChecked()+"",Toast.LENGTH_SHORT).show();
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys can anyone help me with the issue im having with installation of
I'm having issue with Action Listener of a JTable that being updated according the
Is there any issue with having my JavaScript files being served from urls that
In trying to resolve the issue I was having for: managing website on windows
Having issue with my navigation. How can I prevent it? My CSS file looks
My co-worker is having an issue managing customers in his data-base. The issue is
I'm having issue with a youtube video being destroyed properly in a nested belongs_to
I am trying to develop a game and I was having issues managing the
Having issue with slider navigation. Works perfectly fine when there are no other unordered
I having issue that content assistant / intellisense is working in methods such as

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.