【问题标题】:get edittext characters and display into textviews获取edittext字符并显示到textviews
【发布时间】:2014-01-22 13:01:08
【问题描述】:

也许使用 textwatcher 有没有一种方法可以在我的编辑文本中输入一个蓝色的单词,然后 将每个字符拆分并在多个文本视图上设置文本

textview1 显示 b textview2 显示 l textview3 显示你 textview4 显示 e

感谢大家提供的任何帮助。

【问题讨论】:

  • 您为什么不尝试告诉我们这是否可行?这个网站不是为了提供代码,而是帮助解决你在编码时遇到的任何问题。
  • 如果单词是 5 个字母会怎样?

标签: android eclipse textview android-edittext textwatcher


【解决方案1】:
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());

【讨论】:

    【解决方案2】:

    试试这段代码在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();
    
                }
    

    【讨论】:

      【解决方案3】:

      如果您真的想使用 textwatcher,那么您可以使用我的方法,否则 @Digvesh 方法是正确的。首先将 TextWatcher 添加到您的 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());
                               }
                          }
                  };
      

      【讨论】:

        猜你喜欢
        • 2016-06-21
        • 1970-01-01
        • 2012-07-22
        • 1970-01-01
        • 2011-02-27
        • 1970-01-01
        • 2012-11-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多