Issue
For example I made a button where it would take me to another activity and I can input questions there, and I want to lock that button so it cannot be accessed. but after you have input a certain word or like a password that button will unlock. Does anyone know how to implement this? Help please Thank you.
Solution
You can enable and disable any view including buttons
Button btn = findViewById(R.id.button);
makeInteractable(btn,false); // disable button first
private void makeInteractable(View v, boolean interactable){
view.setEnabled(interactable);
}
also you can add TextChangedListener to a EditText and update the button to make it intractable aftercertain data is entered
textfield.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if(conditionMeet())
makeInteractable(btn, true);
}
});
Answered By - Sujan Poudel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.