安卓的EditText替代 [英] Android EditText alternative

查看:623
本文介绍了安卓的EditText替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,Android的的EditText时,用大量的文字(10000 +)的行处理极为缓慢。它出现这样减速部分原因是该支持的EditText跨度,主要是由于这样的事实的EditText是计算每行,这是非常昂贵的宽度的事实。在那里所有的EditText快的替代品,还是有办法来优化它,使其可用?

编辑:痕迹的方法如下:

  android.text.StaticLayout.generate:99.1%的CPU时间的包容性,8.8%独家(1呼叫)
    android.text.Layout.getParagraphSpans:28%包容性,1.1%,独家(4686电话)
    android.text.MeasuredText.setPara:20.6%包容性,1.6%,独家(2343电话)
    android.text.MeasuredText.addStyleRun:18.6%包容性,1.1和放大器;独占(2343电话)
    android.text.SpannableStringBuilder.getSpans:15%(母公司话费)包容性,所有呼叫的56.7%,包括(,其中47.3%来自android.text.Layout.getParagraphSpans,26%来自android.text.MeasuredText.setPara ,26%来自android.text.StaticLayout.generate)
 

解决方案

另一种方法是使用的TextView (怎么回事,你会显示文本),并使其充当的EditText 。具体方法如下:

您将设置一个 OnClickListener 您的TextView,以显示键盘:

  textView.setOnClickListener(新View.OnClickListener(){
    公共无效的onClick(视图v){
        。getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        isEnteringText =真; //全球
    }
});
 

和覆盖的onkeydown 和工艺键盘presses到TextView的:

  @覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
    如果(isEnteringText){
        textView.append(event.getDisplayLabel());
        返回true;
    }
    返回super.onKeyDown(键code,事件);
}
 

显然,这将需要大量的工作,比如隐藏键盘之后,处理退格和放大器;进入,和剪贴板。我还挺形成我的答案围绕<一href="http://stackoverflow.com/questions/14217535/android-softkeyboard-onkeydown-up-not-detecting-alternative-keys">this帖子,你可以尝试在那里提到的,如果你有检索键盘按键问题的其他方法。据他们说,上面的code会一直努力的语言为英语。

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 EditText supports spans, and primarily due to the fact that EditText is calculating the width of each line, which is very expensive. Are there any faster alternatives to EditText, or a way to optimize it to make it usable?

EDIT: Method traces are as follows:

android.text.StaticLayout.generate: 99.1% CPU time inclusive, 8.8% exclusive (1 call)
    android.text.Layout.getParagraphSpans: 28% inclusive, 1.1% exclusive (4686 calls)
    android.text.MeasuredText.setPara: 20.6% inclusive, 1.6% exclusive (2343 calls)
    android.text.MeasuredText.addStyleRun: 18.6% inclusive, 1.1& exclusive (2343 calls)
    android.text.SpannableStringBuilder.getSpans: 15% inclusive (of parent calls), 56.7% inclusive (of all calls, 47.3% of which are from android.text.Layout.getParagraphSpans, 26% are from android.text.MeasuredText.setPara, 26% are from android.text.StaticLayout.generate)

解决方案

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.

这篇关于安卓的EditText替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆