1

テストデバイス: GSM galaxy nexus 4.2 (内蔵キーボードと swiftkey 3 の両方でテスト済み)

私のアプリでは、ユーザーに入力を促すダイアログを作成します。ダイアログには、ユーザーが単語を入力することになっている EditText が表示されます。作成時、およびユーザーが EditText からすべてを消去するたびに、logcat に次のエラー メッセージが表示されます。

SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

ここでスタックオーバーフローを検索するだけでなく、グーグルで検索すると、次のようなものを使用することでエラーを回避できることがわかります

inputBox.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

ここで、inputBox は問題の EditText です。ただし、ユーザーはオートコンプリート可能な単語を入力する必要があるため、オートコンプリート機能を維持したいと考えています。ダイアログの作成に使用されるコードは次のとおりです。

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

私の質問は、オートコンプリート機能を保持しながらエラーの発生を防ぐにはどうすればよいですか?

4

2 に答える 2

1

このプロパティを編集テキストに追加するだけで、問題は確実に解決されます

android:inputType="textNoSuggestions"

上記のプロパティを、アプリケーションで使用される各編集テキストに追加するか、その編集テキストのみでエラーが発生する場所に追加します。

于 2013-04-04T04:06:15.983 に答える
0

I've never seen that particular error before, but my guess is that its this line that causes it:

dialog.getWindow().setSoftInputMode(
        WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

That should open the soft keyboard even when the edit box isn't focused. So the input connection isn't correctly set up, leaving the keyboard with limited functionality. Setting the focus first might help it. So might using LayoutParams.SOFT_INPUT_STATE_VISIBLE without the always- it would prevent the keyboard from having a bad input connection due to not being tied to an editor.

于 2013-02-05T00:56:54.383 に答える