온송정
온송정

Reputation: 37

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
        }
    }
}

Upvotes: 1

Views: 83

Answers (2)

TylerQITX
TylerQITX

Reputation: 328

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

Upvotes: 1

Jaydeep parmar
Jaydeep parmar

Reputation: 569

You need to pass context to QList class and after getting context you can simply call below line

context.getString(R.string.txt_your_string_name)

Upvotes: 0

Related Questions