-1

Using perhaps textwatcher is there a way i can type a word say blue into my edittext and have each character split and set text on multiple textviews

textview1 displays b textview2 displays l textview3 displays u textview4 displays e

thanks to all for any help given.

3 Answers3

2
String str = edittext.gettext().toString();
char[] charArray = str.toCharArray();
Character[] charObjectArray = ArrayUtils.toObject(charArray);


textview1.settext(charObjectArray[0].toString());
textview2.settext(charObjectArray[1].toString());
textview3.settext(charObjectArray[2].toString());
textview4.settext(charObjectArray[3].toString());
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34
0

Try this code working properly in android

String s=t.getText().toString();

            char charArray[] = s.toCharArray();


            for(int i=0;i<charArray.length;i++){

                char r=charArray[i];
                Toast.makeText(getApplicationContext(), ""+r, Toast.LENGTH_LONG).show();

            }
Mohan
  • 311
  • 8
  • 15
0

If you really want to use a textwatcher then you can use my method else @Digvesh method is correct. First of all add a TextWatcher to your editText.

editText.addTextChangedListener(mTextEditorWatcher);

// EditTextWacther  Implementation

                private final TextWatcher  mTextEditorWatcher = new TextWatcher() {

                    public void beforeTextChanged(CharSequence s, int start, int count, int after)
                    {
                                // When No text is Entered

                    }

                    public void onTextChanged(CharSequence s, int start, int before, int count)
                    {
                       // during typing
                    }

                    public void afterTextChanged(Editable s)
                    {
                         String str = edittext.gettext().toString();
                         if(str.length() ==3){
                             char [] characterArray = new char[str.length()];
                             textview1.settext(characterArray [0].toString());
                             textview2.settext(characterArray [1].toString());
                             textview3.settext(characterArray [2].toString());
                             textview4.settext(characterArray [3].toString());
                         }
                    }
            };
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107