Reputation: 1193
I have an EditText that has a stringA stored. When some processes happen, the EditText is updated with a new value (stringB). I have three buttons. I want them disabled while EditText = stringA & updated to enabled when the EditText holds the stringB value.
final EditText latlongText = (EditText) findViewById(R.id.EditText_COord)
This is my EditText. By default, it just holds a string stored in XML as android:hint= "blah blahstringA"
I update it like this in the code:
latlongText.setText(stringB);
In the onCreate, I have:
buttonA.setEnabled(false);
buttonB.setEnabled(false);
buttonC.setEnabled(false);
I'm not sure where or how to correctly place the code to re-enable these buttons.
Perhaps the "clickable" attribute is also an option? I want them to enable when stringB overwrites the value currently stored as the "android:hint" string.
Thanks
Upvotes: 0
Views: 1818
Reputation: 19250
latlongText.addTextChangedListener(new TextWatcher(){
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
String st=latlongText.getText().toString().trim()
if(st.equals(stringA)){
buttonA.setEnabled(false);
buttonB.setEnabled(false);
buttonC.setEnabled(false);
}
else if(st.equals(stringB)){
buttonA.setEnabled(true);
buttonB.setEnabled(true);
buttonC.setEnabled(true);
}
}
});
Upvotes: 2
Reputation: 4171
if(latlongText.getText().equals(stringA)){
buttonA.setEnabled(false);
buttonB.setEnabled(false);
buttonC.setEnabled(false);
}
elseIf(latlongText.getText().equals(stringB)){
buttonA.setEnabled(true);
buttonB.setEnabled(true);
buttonC.setEnabled(true);
}
try this code
Upvotes: 0
Reputation: 3587
have a look on this using textwatcher basically you need to use textwatchers to get to know when your edittext is changed and you can enable/disable button depeding on the text in edittext
Upvotes: 2