Skip to content

Instantly share code, notes, and snippets.

View Dinoy-Raj's full-sized avatar
🤟
stay high

Dinoy Raj Dinoy-Raj

🤟
stay high
View GitHub Profile
Value * Example
WIDE Kotlin, Java, and Xml Use list formatting with full word (no abbrevations)
SHORT Kotlin, Java, & Xml Use list formatting of typical length
NARROW Kotlin, Java, Xml Use list formatting of shortest possible length
Value example *
AND Kotlin, Java, and Xml Conjunction formatting
OR Kotlin, Java, or Xml disjunction formatting
UNITS 1 cm, 2kg, 3km used for formatting list of values with units
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
fun List<String?>?.formatter(type: ListFormatter.Type, width: Width): String {
var formattedValue = ""
try {
ListFormatter.getInstance()
val formatter = ListFormatter.getInstance(Locale.getDefault(), type, width)
formattedValue = formatter.format(this)
} catch (e: Exception) {
Log.d("ListFormatter", "error in formatting list")
}
Locale (region) Result of formatting *
ja_JP ( japan ) Kotlin、Java、Xml separator itself changed
en_US ( US ) Kotlin, Java, and Xml separator before conjunction
en_GB ( UK ) Kotlin, Java and Xml separator not present before conjunction
de_DE ( Germany ) Kotlin, Java und Xml conjunction word
zh_TW ( Taiwan ) Kotlin、Java和Xml conjunction word and spacing in between
ko_KR ( Korea ) Kotlin, Java 및 Xml conjunction word and spacing in between