SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零长度错误,每当一个EditText为空 [英] SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length error whenever an editText becomes empty

查看:7219
本文介绍了SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零长度错误,每当一个EditText为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试设备:GSM Galaxy Nexus的4.2(有两个内置的键盘和swiftkey 3测试)

Test device: GSM galaxy nexus 4.2 (tested with both built in keyboard and swiftkey 3)

在我的应用程序创建一个对话框,提示用户输入。该对话框显示用户应该填一个字其中一个EditText在创建时,以及当用户删除一切从我的EditText收到以下错误消息在logcat中:

In my app I create a dialog to prompt the user for input. The dialog displays an EditText which the user is supposed to fill in a word in. Upon creation, as well as whenever the user erases everything from the EditText I get the following error message in logcat:

SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

谷歌搜索以及搜索位置计算器上告诉我,可避免使用类似

Googling as well as searching here on stackOverflow tells me that the error can be avoided by using something like

inputBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

在这里输入框是EditText上有问题。我不过想保持自动完成功能的用户应该填补话很可能会autocompletable。下面是用于创建对话框中的code:

where inputBox is the EditText in question. I however, would like to keep auto complete functionality as the user is supposed to fill in words that will most likely be autocompletable. Here is the code used to create the dialog:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
final EditText inputBox = new EditText(this);
inputBox.setHint("New keyword");
builder.setTitle(R.string.add_keyword_dialogue_header)
        .setView(inputBox)
        .setPositiveButton("Add",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id {
                            mListAdapter.addItem(inputBox.getText()
                                    .toString());
                        }
                    })
            .setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                                int which) {
                        }
                    });
    final AlertDialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    dialog.show();
    inputBox.requestFocus();

我的问题是,如何从存在的同时保留自动完成功能prevent错误?

My question is, how can I prevent the error from occuring while retaining auto complete functionality?

推荐答案

就在这个属性添加到您的EditText和你的问题一定会得到解决。

Just add this property to your edittext and your problem will definitely be resolved

android:inputType="textNoSuggestions"

添加上述属性您的每一个编辑文本的应用程序中使用,或者干脆在那里你在编辑文本的错误而已。

Add the above property to each of your edit text used in the application, or simply where you get the error in that edit text only.

这篇关于SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一个零长度错误,每当一个EditText为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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