我正在用两种不同的语言制作一个应用程序。
对于应用程序的头部,我使用了以下代码:
private fun showAllResults() {
val listOfAllResult = dbHelperI.getAllQrScannedResult()
showResults(listOfAllResult)
mView.tvHeaderText.text = "Recent Scanned Results"
}
然后我在R.string上创建了文本,但是它显示的是数字,而不是文本。我如何使用R.string对这段代码没有错误?
private fun showAllResults() {
val listOfAllResult = dbHelperI.getAllQrScannedResult()
showResults(listOfAllResult)
mView.tvHeaderText.text = R.string.recent_scanned_results.toString()
}
TextView的setText()
方法有不同的重载。你需要一个以资源id为参数的。
mView.tvHeaderText.setText(R.string.recent_scanned_results)
您需要使用resources
从Id
获取字符串
private fun showAllResults() {
val listOfAllResult = dbHelperI.getAllQrScannedResult()
showResults(listOfAllResult)
mView.tvHeaderText.text = resources.getString(R.string.recent_scanned_results)
}