-
Notifications
You must be signed in to change notification settings - Fork 92
/
AccountsAdapter.kt
31 lines (25 loc) · 1.16 KB
/
AccountsAdapter.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.microsoft.reacttestapp.msal
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
class AccountsAdapter(
context: Context,
private val accounts: MutableList<Account>
) : ArrayAdapter<Account>(context, R.layout.account_item, accounts) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val layoutInflater = LayoutInflater.from(parent.context)
val view = convertView ?: layoutInflater.inflate(R.layout.account_item, parent, false)
val (userPrincipalName, accountType) = accounts[position]
view.findViewById<TextView>(R.id.username).text = userPrincipalName
val accountTypeText = parent.context.resources.getString(R.string.account_type)
view.findViewById<TextView>(R.id.account_type).text =
String.format(accountTypeText, accountType.description())
return view
}
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
return getView(position, convertView, parent)
}
}