2012-09-18 53 views
0

我所要做的是實現一個文本輸入,能夠將字母綠色或紅色。我的一段代碼可以做到這一點,但有一個問題。由於沒有出現彈出窗口,我無法寫出國家信函。國家字母選擇器沒有出現


edit_text.addTextChangedListener(new TextWatcher() { 
    boolean input_changed = false;   

    private boolean isInputBlocked() 
    { 
     this.input_changed = !this.input_changed;     
     return !this.input_changed;     
    } 

    @Override 
    public void afterTextChanged(Editable s) 
    { 
     // Prevent recursive 
     if (isInputBlocked()) return;         

     // Some staff             

     Outer.this.edit_text.setText(Html.fromHtml(html_input.toString())); 
    } 

    @Override 
    public void beforeTextChanged(CharSequence s, int start, int count, 
      int after) {} 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, 
      int count) 
    {}   
}); 

當我評論Outer.this.edit_text.setText(Html.fromHtml(html_input.toString()));,彈出窗口出現。

回答

1

的輸入過濾幫我解決這個問題:

InputFilter filter = new InputFilter() { 
     final String good_letter = "<font color='#2FEE0D'>$</font>"; 
     final String bad_letter = "<font color='#FF0000'>$</font>"; 

     public CharSequence filter(CharSequence source, int start, int end, 
       Spanned dest, int dstart, int dend) 
     { 
      String input = dest.toString().substring(0, dstart) + source. 
        subSequence(start, end) + dest.toString().substring(dend); 
      StringBuffer output = new StringBuffer(); 
      List<Entry<Character, Boolean>> correction = Learn.this. 
       learn_manager.getLetters(input); 

      Log.d(TAG, "afterTextChanged: input size (" + input.length() + 
        ")"); 

      System.out.println(input); 

      for (int i = dstart; i < dstart + end; i++) 
      {      
       if (correction.get(i).getValue()) 
       { 
        output.append(this.good_letter.replace('$', correction. 
          get(i).getKey())); 
       } else { 

        output.append(this.bad_letter.replace('$', correction. 
          get(i).getKey())); 
       } 
      } 

      return Html.fromHtml(output.toString()); 
     } 
};