0

I am making an app in two different languages.

For the header of the app, I used this code.

private fun showAllResults() {
    val listOfAllResult = dbHelperI.getAllQrScannedResult()
    showResults(listOfAllResult)
    mView.tvHeaderText.text = "Recent Scanned Results"

}

Then I made the text on R.string, but it shows numbers, not the text. How can I use R.string on this code without error?

private fun showAllResults() {
    val listOfAllResult = dbHelperI.getAllQrScannedResult()
    showResults(listOfAllResult)
    mView.tvHeaderText.text = R.string.recent_scanned_results.toString()

}
cloud
  • 77
  • 6
  • 2
    That's not how to get the value of the `String` resource. Find some Java solutions [in this question](https://stackoverflow.com/questions/7493287/android-how-do-i-get-string-from-resources-using-its-name)... – deHaar Feb 04 '21 at 09:51

2 Answers2

3

There are different overloads of setText() method for the TextView. You need the one that takes resource id as an argument.

mView.tvHeaderText.setText(R.string.recent_scanned_results)
Konstantin Raspopov
  • 1,565
  • 1
  • 14
  • 20
3

You need to use resources to get the string from Id

private fun showAllResults() {
    val listOfAllResult = dbHelperI.getAllQrScannedResult()
    showResults(listOfAllResult)
    mView.tvHeaderText.text = resources.getString(R.string.recent_scanned_results)
}
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37