Android Include Multiple Same Layout With Kotlin Synthetic Extension

Jul 20, 2019

Include multiple same layout

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <include android:id="@+id/streakLayout" layout="@layout/dailyquote_content_topbar_item" />
    <include android:id="@+id/pointLayout" layout="@layout/dailyquote_content_topbar_item" />
</LinearLayout>

res/layout/dailyquote_content_topbar_item

<?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="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:srcCompat="@drawable/yy_point_acorn"
        />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="100"
        />
</LinearLayout>

Code

pointLayout.imageView.setImageResource(R.drawable.ic_add_black_24dp)pointLayout.textView.text = "Add"streakLayout.imageView.setImageResource(R.drawable.ic_check_black_24dp)streakLayout.textView.text = "Check"

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.