Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText inputType="none" doesn't work, becomes "textMultiLine"

Tested with Android 1.6(4) and 2.3.3(10).

I've made a minimalistic test application to demonstrate this, all it does is load the xml with:

setContentView(R.layout.main); 

and the xml is:

<?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" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="none"
    android:ems="10" >

</EditText>

The problem:

when setting inputType="none" the actual input type during execution becomes textMultiLine(0x00020001), I've checked it with a debugger.

On the other hand if I use inputType="text" it works as expected.

Is this a bug in Android?

like image 642
Roland Avatar asked Apr 18 '12 00:04

Roland


3 Answers

I had the same problem: defining the input type via xml did not work.

Then, to fix it, I set the input type programatically:

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
    {
    ...
    editText1= (EditText) super.getActivity().findViewById(R.id.editText1);
    editText1.setInputType(InputType.TYPE_NULL);    // none...
    ...
    }

That works for me.

like image 185
jsanmarb Avatar answered Oct 19 '22 23:10

jsanmarb


Setting InputType="none" xml doesn't work, but if you're using databinding then you can use the binding syntax to set Input type.

import the type..

<data> <import type="android.text.InputType" /> </data>

then bind the value

<EditText android:id="@+id/edit_text" android:inputType="@{InputType.TYPE_NULL}" />

like image 41
Andronicus Avatar answered Oct 20 '22 01:10

Andronicus


Use android:editable="false". Even though it's deprecated, it works when inputType doesn't.

like image 11
sorianiv Avatar answered Oct 20 '22 01:10

sorianiv