Ad
After Calling SetEnabled(false) Button Still Can Be Pressed One More Time
When clicking a button I immediately call setEnabled
to false however this does not disable the button and I have to press again to disable.
I have tried to put setEnabled
in different places but with the same result.
chooseLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
chooseLeft.setEnabled(false);
chooseRight.setEnabled(true);
docRefPosts.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
if(!chooseRight.isEnabled())
docRefPosts.update("votesForRight", FieldValue.increment(-1));
docRefPosts.update("votesForLeft", FieldValue.increment(1));
}
}
});
}
});
chooseRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
chooseRight.setEnabled(false);
docRefPosts.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
if(!chooseLeft.isEnabled())
docRefPosts.update("votesForLeft", FieldValue.increment(-1));
docRefPosts.update("votesForRight", FieldValue.increment(1));
}
}
});
chooseLeft.setEnabled(true);
}
});
It should function as a radio button where once selected only one can be chosen at a time.
Ad
Answer
I found the answer and I only have a guess as to why it is working. What I did was move all the code for the OnCompleteListener
into a separate method. I think that the listener was running before the app could register setEnabled(false)
. If anyone has any thoughts on this reasoning I would love to hear.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad