Android 4.0 EditText без программной клавиатуры и с позиционированием курсора

Я пытаюсь определить поле EditText без автоматического отображения экранной клавиатуры при касании окна. Мне также нужно, чтобы мигающий курсор отображался и перемещался в зависимости от касания. Это легко сделать до Android 4.0, просто используя mText.setInputType (InputType.TYPE_NULL). Это единственный способ подавить автоматическое отображение программной клавиатуры, но в Android 4.0 он также подавляет мигающий курсор. Курсор, однако, позиционируется правильно, а mText.getSelectionStart () возвращает последнее местоположение касания. Например, если я коснусь между «2» и «3» в поле EditText, содержащем «123», mText.getSelectionStart () правильно вернет 2, даже если курсор не отображается. Есть ли способ программно отобразить курсор в этом месте?

Вот код, который я использую для проверки местоположения курсора EditText:

public class TestCodeActivity extends Activity implements OnClickListener {
        private EditText mText;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
                getApplicationContext();
                setContentView(R.layout.test);
                findViewById(R.id.Button01).setOnClickListener(this);
                findViewById(R.id.Button02).setOnClickListener(this);
                findViewById(R.id.Button03).setOnClickListener(this);
                findViewById(R.id.Button04).setOnClickListener(this);
                mText = (EditText) findViewById(R.id.editText1);
                mText.setInputType(InputType.TYPE_NULL);
        }

        @Override
        public void onClick(View v) {
            if (v.getTag().equals("Clear")) {
                mText.setText("");
            } else {
                String buttontag = v.getTag().toString();
                String str = mText.getText().toString();
                int cursor = mText.getSelectionStart();
                if(cursor==str.length())
                    str = str + buttontag;
                else
                    str = str.substring(0, cursor) + buttontag + str.substring(cursor, str.length());
                mText.setText(str);
                mText.setSelection(cursor+1);
                // ---> need code to display blinking cursor at cursor+1 location ???
        }
        }
    }

Вот макет XML:

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="85dp" >
        <EditText
            android:id="@+id/editText1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.13"
            android:ems="10"
            android:textSize="25sp" >
            <requestFocus />
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/Button01"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:text="1"
            android:tag="1"
            android:layout_gravity="center"
            android:textSize="30sp" />
        <Button
            android:id="@+id/Button02"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:text="2"
            android:tag="2"
            android:layout_gravity="center"
            android:textSize="30sp" />
        <Button
            android:id="@+id/Button03"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:text="3"
            android:tag="3"                        
            android:layout_gravity="center"
            android:textSize="30sp" />
        <Button
            android:id="@+id/Button04"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:text="Clear"
            android:tag="Clear"                        
            android:layout_gravity="center"
            android:textSize="30sp" />
    </LinearLayout>

</LinearLayout>

Ответы на вопрос(1)

Ваш ответ на вопрос