Java – Prevents double-clicking OnClickListener

Prevents double-clicking OnClickListener… here is a solution to the problem.

Prevents double-clicking OnClickListener

I’m trying to prevent users from clicking my button twice. I tried using setEnabled in my script but nothing happens! My problem is, I’m trying to do this in setOnClickListener.

Can someone help me find a solution to prevent clicks from happening when everything is uploaded to the server?

newPostBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
         I want to set my button to enabled false here


Why not use setOnAction?

newPostBtn.setOnAction(e -> {
    (your logic goes here)

}) ;

Related Problems and Solutions