Android EditText alternative

前端 未结 4 745
醉话见心
醉话见心 2020-12-16 12:29

Currently, Android\'s EditText is extremely slow when dealing with a huge amount of lines of text (10000+). It appears like this slowdown is partially due to the fact that E

4条回答
  •  情话喂你
    2020-12-16 12:57

    The alternative would be to use a TextView (how else would you show the text) and make it act as a EditText. Here's how:

    You'll set an OnClickListener on your TextView, to show the keyboard:

    textView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            isEnteringText = true; //global
        }
    });
    

    And override onKeyDown and process keyboard presses to the TextView:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(isEnteringText) {
            textView.append(event.getDisplayLabel());
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    

    Obviously this will need a lot of work, such as hiding the keyboard afterward, processing backspace & enter, and clipboard. I kinda formed my answer around this post, you can try the other methods mentioned in there if you're having problems retrieving the keyboard keys. According to them, the above code will work as long as the language is English.

提交回复
热议问题