Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Button on click

I am newbie to the programming world and my knowledge is limited. Please excuse me if i ask any blunder. My question is that.

I am creating an Activity which has START & STOP button. when user clicks on START button a service must start; and on STOP service must stop.

Now I want to disable my START button when i Click start button(service starts on click START button) and when clicks STOP button i want to see the START button as normal clickable button.

I have used .setEnabled(false) by creating the button object. i need help...Thanks in advance

like image 464
ADD Avatar asked Mar 23 '12 12:03

ADD


People also ask

How do you disable a button when it is clicked?

1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.

How do I make a button disabled after 3 clicks?

function clickFunc() { count += 1; //lets say id of button is btn if(count>3){ $('#btn'). prop('disabled', true); } } });


1 Answers

int count = 0;

if (count == 0) {
    stop.setEnabled(false);
    PlayButton.setEnabled(true);
}

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.play:
            count++;
            play.setEnabled(false);
            Toast.makeText(this, "Button Disabled", Toast.LENGTH_LONG).show();
            Stopbutton.setEnabled(true);
            break;

        case R.id.stop:
            Toast.makeText(this, "Button Disabled", Toast.LENGTH_LONG).show();
            count--;    
            PlayButton.setEnabled(true);
            stop.setEnabled(false);
            break;        
    }
}

& check this link How to disable an Android button?

like image 182
Amandeep singh Avatar answered Oct 30 '22 02:10

Amandeep singh