Cómo establecer el texto Min (obligatorio) y el texto máximo en edittext

En mi cuadro de texto de edición, quiero dar un poco de texto mínimo como obligatorio y el texto de Max tener alguna limitación como la que quiero dar en mi cuadro de edittext, es esto cualquier manera está allí para dar así en mi valor de EditText.

Si vamos a escribir texto el recuento de numérico tiene que disminuir como that.How que hacer que uno.

<EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/textView1" android:layout_marginTop="24dp" android:maxLength="175" android:ems="10" /> 

Esta es mi actividad add.java

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home_layout); System.out.println(PRAYER_CATEGORY.length); tvPrayer = (TextView) findViewById(R.id.mystate); spinnerPrayers = (Spinner) findViewById(R.id.spinnerstate); ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, PRAYER_CATEGORY); adapter_state .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerPrayers.setAdapter(adapter_state); value=(EditText)findViewById(R.id.editText1); value .setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if (hasFocus) { if (value.getText().toString().trim() .length() < 3) { value.setError("Failed"); } else { value.setError(null); } } else { if (value.getText().toString().trim() .length() < 3) { value.setError("Failed"); } else { value.setError(null); } } } }); btnSpeakprayer = (ImageButton) findViewById(R.id.btnSpeakprayer); btn=(Button)findViewById(R.id.button1); pb=(ProgressBar)findViewById(R.id.progressBar1); pb.setVisibility(View.GONE); btn.setOnClickListener(this); 

O simplemente puede cambiar su código a este

 value.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if (hasFocus) { if (value.getText().toString().trim() **try using value.getText().length()<3** .length() < 3) { **instead of the value.getText().trim().length()** value.setError("Failed"); } else { value.setError(null); }}}}); 

Puedes probar este código

Primero de todo usted fija su maxlength en archivo xml como este

  <EditText android:id="@+id/editText" android:layout_width="match_parent" android:inputType="textPassword" android:lines="1" android:maxLength="15" android:maxLines="1" android:singleLine="true" /> 

Entonces en tu código puedes escribir así

 et_billamt.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { if (et_billamt.getText().toString().trim().length() < 5) { et_billamt.setError("Failed"); } else { // your code here et_billamt.setError(null); } } else { if (et_billamt.getText().toString().trim().length() < 5) { et_billamt.setError("Failed"); } else { // your code here et_billamt.setError(null); } } } }); 

Diseñé si después de ninguÌ n foco, tan aquí usted puede escribir para la condición min de la longitud y la condición de la longitud máxima

 Try this 
 EditText value =(EditText) findviewbyId(R.id.urEditTextId);// this line must be oncreate 

// Coloca esta línea donde quieras comprobar

 String ed1=value .getText().toString(); int size=ed1.length(); 

Usted puede emparejar el dígito y realizar la acción apropiada

 if(size==0) //Toast : kindly enter atleast one letter if(size>175) //Toast : max length 175 char 

Puede extender la clase EditText y reemplazar el método onTextChanged para supervisar el cambio de longitud de texto por usted mismo. A continuación, puede controlar la limitación.

 public class CustomEditText extends EditText{ public CustomEditText(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { // TODO Auto-generated method stub Log.i("length", "input text length = " + text.length()); super.onTextChanged(text, start, lengthBefore, lengthAfter); } 

}

Aquí está un EditText y un botón:

 EditText myEditText; Button button; 

En su onCreate ():

 myEditText = (EditText) findViewById(R.id.edittext); button = (Button) findViewById(R.id.button); 

Digamos que envíe o utilice el valor que un usuario escribe en myEditText mediante el botón. Establezca 'OnClickListener' en este botón:

 button.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mEditText.length() < 1 || mEditText.length() > 175) { mEditText.setError("Value should be between 1 and 175 characters in length"); mEditText.requestFocus(); } else { // Value is valid (between 1 and 175 characters long) String text = mEditText.getText().toString(); // submit } } }); 
  • Convertir APK en JAR
  • Automatización del emulador y navegador de Android con la secuencia de comandos de Appium
  • Qué es la longitud de nombre variable?
  • ¿Cómo convertir una cadena a UTF-8 en Android?
  • Cómo almacenar Lista de dispositivos adb en la red en php array
  • Visibilidad de diseño y vistas en la aplicación
  • Convertir todo el contenido en un ScrollView a un mapa de bits?
  • Cómo y qué establecer en Android WifiConfiguration.preSharedKey para conectarse a la red WPA2 PSK WiFi
  • Problemas de serialización java con JVM diferentes
  • Android: ¿Cómo obtener el color de fondo de Actividad en Java?
  • ¿Cómo puedo hacer que mi ArrayAdapter siga el patrón ViewHolder?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.