Oto mój kod do okna, chcę wyłączyć pozytywny przycisk, jeśli rozmiar tekstu w edycji tekstu w większy niż 5 i włączyć go, jeśli rozmiar < = 5Android wyłączyć pozytywny przycisk na jakimś condion w addTextChangedListener (editext)
private void myDialog(String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
// Get the layout inflater
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.new_dialog, null);
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(dialogView);
final EditText dialogEdittext = (EditText) dialogView.findViewById(R.id.dialog_editText);
final TextView dialogMessage = (TextView) dialogView.findViewById(R.id.dialog_limit);
dialogEdittext.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) {
// if text length is greater than 5 disable positive button
// else enable
}
});
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
final Dialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
dialog.show();
}
odsyłaj ten link http://stackoverflow.com/questions/8238952/how-to-disable-enable-dialog-negative-possitive-buttons –
Widziałem już to łącze, to będzie wyłączać/włączać przycisk tylko raz, gdy okno dialogowe jest utworzone, ale chcę to za każdym razem, gdy użytkownik wprowadza znak w edytorze tekstu – Androider
Nigdy nie robię tego w ten sposób. Zrobiłem to za pomocą niestandardowego okna dialogowego z przyciskiem iw tym sprawdzam sprawdzanie poprawności. możesz to zrobić w ten sposób. spróbuj tego –