Prevent double click on OnClickListener

Alexandre Gagné :

I tried to prevent the user from clicking on my button twice. I tried to use setEnabled on my script but nothing happens! My problems are, I tried to do this in setOnClickListener.

Can someone please help me to find a solution to prevent clicking while everything is being uploaded to the server?

newPostBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // I want to set my button to enabled false here
    }
}
bakero98 :

Why not use setOnAction?

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

    newPostBtn.setEnabled(false);
}) ;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=98495&siteId=1