android - EditText滞后

时间:2013-03-31 11:08:05

标签: android android-emulator android-edittext

我有一个edittext(12)数组,以这种方式进行了初始化:

for (int i = 0; i < solution.length(); i++) {
            int resID = context.getResources().getIdentifier(idName + i, "id",
                    context.getPackageName());
            editText[i] = (EditText) layout.findViewById(resID);
            editText[i].setVisibility(View.VISIBLE);
            editText[i].setEnabled(true);
            editText[i]
                    .setFilters(new InputFilter[] { new InputFilter.AllCaps(),
                            new InputFilter.LengthFilter(1) }); 

}

我的xml是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutsolutionhorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top|center_vertical|center_horizontal" >

    <EditText
        android:id="@+id/txtsolutionhorizontal0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal0"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal1"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal2"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal3"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal4"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal5"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal6"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal7"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal8"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal9"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/txtsolutionhorizontal11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal10"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="center"
        android:inputType="text|textNoSuggestions"
        android:padding="0dp"
        android:singleLine="true"
        android:textSize="15dp"
        android:visibility="gone" >
    </EditText>

    <ImageView
        android:id="@+id/buttonclearhorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/txtsolutionhorizontal11"
        android:clickable="true"
        android:src="@drawable/clearbox" />

</RelativeLayout>

对于每个edittext都有一个监听器:

for (int j = 0; j < editTextVertical.length; j++) {
                    editTextVertical[j]
                            .addTextChangedListener(new EditTextInputTextWatcherListener(
                                    editTextVertical, editTextVertical[j], j));
                }

EditTextInputTextWatcherListener是:

public void onTextChanged(CharSequence s, int start, int before, int count) {
        // System.out.println(s.charAt(count-1) + " character to send");
        if (editText1.getText().toString().length() == 1
                && !editText1.getText().toString().equals("")) {
            if (index < 11)
                editText[index + 1].requestFocus();
        } else if (editText1.getText().toString().length() == 0
                && editText1.getText().toString().equals("")) {
            editText[index].requestFocus();
        }
    }

如果edittext是3或5是好的,但是当edittext更大时,我输入文本时会有很多延迟。 如果我在编辑文本中写了一封信,我会在1s之后看到这封信。

我在模拟器和设备上遇到了这个问题。 有可能解决问题吗?

非常感谢

0 个答案:

没有答案