How to return a Boolean on the button

Asked

Viewed 280 times

1

I have a button and I want when it’s clicked to return true in a if of another class, but I haven’t found any method of how I do it.

Button b = new Button();

Other class:

public static ObservableList getObs(ObservableList<String> obs,ObservableList<String> obs2){ 
    if(Main.b.algumMetodo() == true){
        return obs2;
    }else if(Main.b.algumMetodo() != true){
        return obs;
    }
    return obs;
}

How do I do that?

1 answer

1


To receive a notification when the button is clicked:

     b.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             // Acão, código aqui é executado.
         }
     });

Edit:

The problem is that the button will only be in the clicked state a few milliseconds - so unless you are calling the function very often the probability of being true is very, very low.

What I could do is put a proper boolean in the OnClickListener where you can change the state as you like (after a second? 10 seconds? with Thread.sleep(), on his own Thread, I don’t know what it takes. After the other job is evaded?).

  • But do not to make it because within the if will have to return an Observablelist, I will edit the question.

  • Actually my problem is that he can’t change the Observablelist

  • I edited the answer too. Good luck!

  • What is this View v? Ain’t that Swing?

  • It’s the button that was clicked.

  • I’m sorry, I still don’t understand. But just re-exporting I want that when I click the button it returns the Obs(Observablelist) and if I click again return the other Observablelist(Obs2).

  • It worked, I did it the way you said and I did it, thank you!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.