Could you review it and said if it's written good and/or is better way to do that?
My algorithm is:
Input roomNumber If length of roomNumber is 8 set goToRoom state Enabled and color 0xFFFFFFFF Else set goToRoom state Disabled and color 0xBBFFFFFF
Code of that algorithm is:
public class Join_room_screen extends Activity {
EditText numberRoom;
Button goToRoom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.joinroom);
numberRoom = (EditText) findViewById(R.id.roomNumber);
goToRoom = (Button) findViewById(R.id.goToRoom);
TextWatcher watcher = new LocalTextWatcher();
goToRoom.addTextChangedListener(watcher);
updateButtonState();
}
void updateButtonState() {
boolean enabled = checkEditText(numberRoom);
if (enabled) {
goToRoom.setBackgroundColor(0xFFFFFFFF);
goToRoom.setEnabled(enabled);
} else {
goToRoom.setBackgroundColor(0xBBFFFFFF);
goToRoom.setEnabled(false);
}
}
private boolean checkEditText(EditText edit) {
return ((edit.getText().toString()).length() == 8 );
}
private class LocalTextWatcher implements TextWatcher {
public void afterTextChanged(Editable s) {
updateButtonState();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
}