Domanda

Come posso misurare la lunghezza di stringa inserita nel EditText mentre typing.Because voglio mostrare un avviso quando la lunghezza del testo inserito attraversare 100 caratteri. Grazie in anticipo.

È stato utile?

Soluzione

È possibile utilizzare TextWatcher al EditText di farlo in Android.

Qualcosa di simile a questo

 EditText test = new EditText(this);
        test.addTextChangedListener(new TextWatcher() {

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try {
                   //write your code here
                } catch (NumberFormatException e) {
                }
            }
            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub

            }
        });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top