androidkotlingetstring

Is there a way to use getString inside a util?


I succeeded in getString using getSystem. But I want to know how to use local string. If you know the answer to this problem, can you help me? Thanks in advance for those of you who know the answer.

class QList {
    companion object {
        val qList = listOf(
            Resources.getSystem().getString(android.R.string.cancel),
           "AAAA", "BBBB", "CCCC"
        )

        fun getQList(): ArrayList<Question> {
            var qlist = ArrayList<Question>()

            for(num in qList.indices) {
                qlist.add(Question(num + 1, qList[num], "", ""))
            }

            return qlist
        }
    }
}

Solution

  • getString using getSystem should work for local string, just import your project's .R to your utils class.