Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/txt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:textColor="#1b3c59"
android:textSize="21sp"
tools:text="Title"
class TitleAdapter(private val title: Title) : RecyclerView.Adapter<TitleAdapter.DataViewHolder>() {
class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(title: Title) {
itemView.txt_title.text = title.text
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
DataViewHolder(
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
class HeaderAdapter(private val header: Header) :
RecyclerView.Adapter<HeaderAdapter.DataViewHolder>() {
class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(header: Header) {
itemView.frm_color.setBackgroundColor(header.color)
itemView.txt_header.text = header.text
}
}
object MergeAdapterDataSource {
fun getHeader() = Header(Color.BLUE, "RECYCLERVIEW")
fun getTitle() = Title("Merge Adapter")
fun getImage() = Image(R.drawable.placeholder)
}
data class Header(val color: Int = 0,
val text: String = "")
data class Title(val text: String = "")
data class Image(val image: Int = 0)
<uses-permission android:name="android.permission.INTERNET"/>
apiClient.getUserFromApi { isSuccess, response, message ->
if (isSuccess) {
val name = response?.documents?.first()?.fields?.name
val surname = response?.documents?.first()?.fields?.surname
name?.let { _name ->
txt_name.text = _name.stringValue
}
surname?.let { _surname ->
txt_surname.text = _surname.stringValue
}
private val apiClient by lazy { ApiClient() }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">