scottiedog45
11/06/2019, 12:36 PMz is a textView:
z.text = z.context.getString(R.string.empty)tseisel
11/06/2019, 1:11 PMContext that outlives the `Fragment`/`Activity` where the View is defined (this would result in memory leaks).
Note that in your sample code, you could have used z.setText(R.string.empty), which internally does what your code is doing : accessing resources from its Context.Alex Crafford
11/06/2019, 1:23 PMz.text = resources.getString(R.string.empty)
or
z.text = ""scottiedog45
11/06/2019, 1:29 PMcontext parameter:
fun replaceEmptyDataWithLiteralEmptyStringIfNeeded(c: Context, textViews: List<TextView>, data: List<String?>) {
(textViews zip data).forEach { z ->
if (!z.second.isNullOrEmpty()) {
z.first.text = z.second
z.first.setTypeface(null, Typeface.NORMAL)
} else {
z.first.text = c.getString(R.string.empty)
z.first.setTypeface(null, Typeface.ITALIC)
}
}
}Alex Crafford
11/06/2019, 1:31 PMscottiedog45
11/06/2019, 1:32 PMgetString. Ah- that empty string is literally the word “empty” 😅Alex Crafford
11/06/2019, 1:33 PMscottiedog45
11/06/2019, 1:34 PMAlex Crafford
11/06/2019, 1:37 PMAlex Crafford
11/06/2019, 1:42 PMscottiedog45
11/06/2019, 2:01 PM