I have this layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:id="@+id/txt_daytime"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-medium"
android:text="-"
android:textColor="@color/gray"
android:textSize="16sp" />
<TextView
android:id="@+id/txt_temp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-medium"
android:text="-"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
I want to add it to my linear layout in main layout:
<LinearLayout
android:id="@+id/temp_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:orientation="horizontal">
in code. I'm using this:
val dayTime = listOf(DayTime.NIGHT, DayTime.MORNING, DayTime.DAY, DayTime.EVENING)
val tempContainer = binding.tempContainer
for (temp in dayTime) {
val weather = weatherData.getWeather(temp)
val view = LayoutInflater.from(requireContext()).inflate(R.layout.temp_layout, tempContainer) as LinearLayout
view.apply {
layoutParams = (layoutParams as LinearLayout.LayoutParams).apply {
weight = 1f
}
}
but how can i set values to those two TextViews in my reusing layout in code? When i'm trying to get children in this view i can't choose TextView and also i can't set values to this children