Zim
Zim

Reputation: 396

Parameterize id names

Is there a better way of doing this? Hopefully, to shorten the lines?

when (tabKey) {
        1 -> {
            learnHeader!!.id        = R.id.learnHeader1
            learnSwipeRefresh!!.id  = R.id.learnSwipeRefresh1
        }

        2 -> {
            learnHeader!!.id        = R.id.learnHeader2
            learnSwipeRefresh!!.id  = R.id.learnSwipeRefresh2           
        }
}

Something like:

            learnHeader!!.id        = R.id.learnHeader + tabKey
            learnSwipeRefresh!!.id  = R.id.learnSwipeRefresh + tabKey

Upvotes: 0

Views: 43

Answers (1)

sushildlh
sushildlh

Reputation: 9056

try this ....

int idHeader[]={R.id.learnHeader1,R.id.learnHeader2};
int idSwipeRefresh[]={R.id.learnSwipeRefresh1,R.id.learnSwipeRefresh2};



tabKey--;

learnHeader!!.id        =idHeader[tabKey]
learnSwipeRefresh!!.id  = idSwipeRefresh[tabKey]

Hope it help you.....

Upvotes: 1

Related Questions