Android EditText alternative

﹥>﹥吖頭↗ 提交于 2019-11-30 11:10:16

The best thing you can do is using RecyclerView with EditText as its item, so you get a new EditText for each of your lines.

New line will be the only thing you will have to implement.

Although this article only talks about optimizing static TextViews where the text doesn't change, it might get you on the right track for making a more performant EditText.

Avoid using EditText inside a RelativeLayout, use LinearLayout instead.

Aaron Gillion

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.

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