National letter selector doesn't appear

此生再无相见时 提交于 2019-12-12 01:13:58

问题


What I had to do was to implement a text input able to color letters green or red. My piece of code can do this but there is a problem. I can't write an national letter because the popup does not appear.


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) 
    {}        
});

When I commented Outer.this.edit_text.setText(Html.fromHtml(html_input.toString()));, the popup appears.


回答1:


The InputFilter helped me resolve the problem:

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());
        } 
};


来源:https://stackoverflow.com/questions/12485702/national-letter-selector-doesnt-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!