Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText hint error in Android

Tags:

android

I am trying to set hint to be question mark (?). If I set it as string in xml file I get error

Error: Resource id cannot be an empty string (at 'hint' with value '?').

<EditText
        android:id="@+id/txt_to_edit"
        android:layout_width="92dp"
        android:layout_height="wrap_content"
        android:layout_column="8"
        android:layout_gravity="bottom"
        android:layout_row="5"
        android:layout_rowSpan="6"
        android:hint="?"
        android:text="@string/txt_label"/>

If I set the hint to point at @string/quest in strings.xml I get the same error. If I try to use ! or anything similir it works fine. I am using Android SDK 4. Thanks

<EditText
            android:id="@+id/txt_to_edit"
            android:layout_width="92dp"
            android:layout_height="wrap_content"
            android:layout_column="8"
            android:layout_gravity="bottom"
            android:layout_row="5"
            android:layout_rowSpan="6"
            android:hint="@string/quest"
            android:text="@string/txt_label"/>
like image 644
GuyWhoReadsStockoverflow Avatar asked Dec 27 '22 04:12

GuyWhoReadsStockoverflow


2 Answers

? is considered as a special character (used for ?android:attr for example). Try with \?.

like image 168
Amokrane Chentir Avatar answered Dec 29 '22 19:12

Amokrane Chentir


I agree with Amokrane.

Maybe try

<EditText
    android:id="@+id/txt_to_edit"
    android:layout_width="92dp"
    android:layout_height="wrap_content"
    android:layout_column="8"
    android:layout_gravity="bottom"
    android:layout_row="5"
    android:layout_rowSpan="6"
    android:hint="\?"
    android:text="@string/txt_label"/>
like image 41
David West Avatar answered Dec 29 '22 19:12

David West