Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] Why do we need to add @SuppressLint(“SetTextI18n”) annotation before concatenating strings in Android Studio

Posted on November 11, 2022 By

Solution 1 :

“I18” stands for “Internationalization”. Android’s localized resources mechanism allows you to support a variety of locales without having to modify your code. For example, here’s how it could look if your application had to support multiple currencies:

In res/values-en_US/strings.xml:

<string name="price">%d$</string>

In res/values-en_UK/strings.xml:

<string name="price">%d£</string>

In res/values-de/strings.xml:

<string name="price">%d€</string>

Then your code would automatically pick up the correct version based on the device’s locale:

fun displayPrice(number: Int) {
    price_text_view.text = resources.getString(R.string.price, number)
}

If your application only supports currencies with the $ symbol then it makes sense to hardcode it and use @SuppressLint("SetTextI18n") to silence the warning. Otherwise, consider using string resources.

Problem :

I tried the following code for concatenation of ‘number'(integer variable) and ‘$'(string) but I got a warning from android studio: “Do not concatenate text displayed with setText. Use resource string with placeholders.” and suggested me to add “@SuppressLint("SetTextI18n")“. After this the warning was gone.

What was the issue with concatenating the string. And why do we need to add

@SuppressLint("SetTextI18n")
fun displayPrice(number: Int){
    price_text_view.text= "$number$"
}
READ  [FIXED] Zoom controls for MapBox Android
Powered by Inline Related Posts
Android Tags:android, concatenation, kotlin, settext, string

Post navigation

Previous Post: [FIXED] How to get Firebase auth token in Android login
Next Post: [FIXED] android – what should be the input and output forom of variables for float object detection model

Related Posts

[FIXED] java – How to i display ALL of my data from Firebase Realtime Database in to TextView Android
[FIXED] android – Jetpack Paging Library load all pages without scrolling Android
[FIXED] Content in textview not showing (Android Studio) Android
[FIXED] Android: app-ads.txt file for Facebook Audience Network Android
[FIXED] java – How can i make menu like the picture below in android Android
[FIXED] alarmmanager – How to use Alarm Manager on Android 9 and Android 10? Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme