Warning on EditText

2019-03-12 23:58发布

I'm trying to define an EditText but this warning is shown:

This text field does not specify an inputType or a hint.

The code in main.xml is:

<EditText android:id="@+id/input" 
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content" 
              android:text="@string/textTest" /> 

How can I fix it?

4条回答
forever°为你锁心
2楼-- · 2019-03-13 00:26

You could add a hint :

android:hint="This will appear to the user if he didn't enter something yet in the EditText"

and a inputType so you could present to the user a better suited soft keyboard for the text he is suposed to enter in the EditText:

android:inputType="number"

will present a soft keyboard with only numbers and various signs.
Those are just warnings, you could ignore them but is better for the user to implement them.

查看更多
看我几分像从前
3楼-- · 2019-03-13 00:26

This is a known issue. Sometimes it doest work with changing to:

android:inputType="text"

I got it to work by setting:

android:inputType="textNoSuggestions"

Hope this helps

查看更多
看我几分像从前
4楼-- · 2019-03-13 00:35
 <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:inputType="text"
        >  

I think You should add input type.......

查看更多
Ridiculous、
5楼-- · 2019-03-13 00:44

Above all are the solutions but before that you should understand what does that warnig mean.

Hint:- Hint is the text shown to user before writing anything over. For eg. if you are putting a edittext where you want user to add his name then you can write

<Edittext
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:hint="Enter Name"/>

Input Type:- This is the xml tag that is to be used within edittext to let edittext to follow that particular restriction. if you are giving inputtype:number then user would be able to enter only numbers. There are several input type fields are there for that you can refer official developer site.

查看更多
登录 后发表回答