• 8
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Disable other buttons when Record button active

I have 4 items in the menu and 1 button Rec / Stop. I want, when the Rec button is active and records, the other 4 items in the menu items are disabled. Please help me.

this is activity_main.xml

<ToggleButton
    android:id="@+id/recStop"
    android:layout_width="65dp"
    android:layout_height="65dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="100dp"
    android:background="@drawable/tbutton"
    android:text=""
    android:textOff=""
    android:textOn="" />

this is tbutton.xml

<item android:drawable="@drawable/rec"
android:state_checked="false" />

<item android:drawable="@drawable/stop"
android:state_checked="true" />

this is MainActivity.java

private ToggleButton toggleButton;

toggleButton = (ToggleButton) findViewById(R.id.recStop);

// Button Rec / Stop
toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView,
                                 boolean isChecked) {

        if (isChecked) {
            speech.setRecognitionListener(VoiceRecognitionActivity.this);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setIndeterminate(true);
            speech.startListening(recognizerIntent);
        } else {
            progressBar.setIndeterminate(false);
            progressBar.setVisibility(View.INVISIBLE);
            speech.stopListening();
            speech.destroy();

        }

    }
});

this is MainActivity.java

// Menu items
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
    case R.id.copy:
        break;
}
switch (item.getItemId()) {
    case R.id.share:
        break;
}
switch (item.getItemId()) {
    case R.id.clear:
        break;
}
switch (item.getItemId()) {
    case R.id.about:
        break;
}
return super.onOptionsItemSelected(item);
}

Inside each condition of your switch...case, check the status of togglebutton and if its checked avoid further actions in it. Also don't use multiple switch, you must define multiple cases inside it see the code below.

switch (item.getItemId()) {
    case R.id.copy:
        if(toggleButton.isChecked()) {
             //display warning message
        } else {
             // your regular code here
        }
        break;

    case R.id.share:
        if(toggleButton.isChecked()) {
             //display warning message
        } else {
             // your regular code here
        }
        break;

    case R.id.clear:
        if(toggleButton.isChecked()) {
             //display warning message
        } else {
             // your regular code here
        }

        break;

    case R.id.about:
        if(toggleButton.isChecked()) {
             //display warning message
        } else {
             // your regular code here
        }
        break;
}
  • 1
Reply Report

You can achieve that with this code

  switch (item.getItemId()) {
   case R.id.copy:
    if(toggleButton.isChecked()) {
          menu.findItem(R.id.copy).setEnabled(false);
    } else {
         menu.findItem(R.id.copy).setEnabled(true);
    }
    break;

//you do the same for the rest of menu buttons
 }
  • 0
Reply Report