String in hard coding EditText used as integer value

advertisements

I have a EditText in my xml file. But i use a default value "1" as the text for the EditText. I know why I shouldn't hardcode strings but it is a integer value that always has "1" as default. so should I still enter the value in a string or should I ignore themessage?


As for me, it's ok to ignore the warning in your scenario. Anyway, if you want to get rid of it, you could declare an integer instead of a string (in a resource file integers.xml for instance), like.-

<integer name="integer1">1</integer>

And set it in your TextView

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@integer/integer1" />