Question: How to make CardView which will contain the n-th number of textView? If I understand correctly this is a custom element, then is it necessary to do this through code? Now it is strictly stated that only 4 textView for minutes.
ViewHolder code (a):
class ScheduleViewHolder( inflater: LayoutInflater, container: ViewGroup) : RecyclerView.ViewHolder(inflater.inflate(R.layout.item_schedule, container, false)) { @BindView(R.id.textView_hour) lateinit var hour: TextView @BindView(R.id.textView_minute_first) lateinit var minuteFirst: TextView @BindView(R.id.textView_minute_second) lateinit var minuteSecond: TextView @BindView(R.id.textView_minute_third) lateinit var minuteThird: TextView @BindView(R.id.textView_minute_fourth) lateinit var minuteFourth: TextView init { ButterKnife.bind(this, itemView) } fun bind(data: TimeViewData) { hour.text = data.hour minuteFirst.text = data.minuteFirst minuteSecond.text = data.minuteSecond minuteThird.text = data.minuteThird minuteFourth.text = data.minuteFourth } } The markup of my CardView is:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="1dp" android:layout_marginLeft="1dp" android:layout_marginRight="1dp" android:layout_marginStart="1dp" card_view:cardBackgroundColor="@android:color/transparent" card_view:cardElevation="0dp" card_view:cardUseCompatPadding="true"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/textView_hour" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/colorLightGray" android:gravity="center" android:maxLines="1" android:paddingBottom="24dp" android:paddingLeft="24dp" android:paddingRight="24dp" android:paddingTop="24dp" android:textAppearance="@style/ScheduleScreen.Text.Hours" android:textStyle="bold" tools:text="14 ч." /> <TextView android:id="@+id/textView_minute_first" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@color/colorLightGray" android:gravity="center" android:paddingBottom="8dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="8dp" android:textAppearance="@style/ScheduleScreen.Text.Minute" tools:text="10 мин." /> <TextView android:id="@+id/textView_minute_second" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@color/colorLightGray" android:gravity="center" android:paddingBottom="8dp" android:paddingTop="8dp" android:textAppearance="@style/ScheduleScreen.Text.Minute" tools:text="25 мин." /> <TextView android:id="@+id/textView_minute_third" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@color/colorLightGray" android:gravity="center" android:paddingBottom="8dp" android:paddingTop="8dp" android:textAppearance="@style/ScheduleScreen.Text.Minute" tools:text="45 мин." /> <TextView android:id="@+id/textView_minute_fourth" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="8dp" android:layout_weight="1" android:background="@color/colorLightGray" android:gravity="center" android:paddingBottom="8dp" android:paddingTop="8dp" android:textAppearance="@style/ScheduleScreen.Text.Minute" tools:text="55 мин." /> </LinearLayout> </android.support.v7.widget.CardView> Task setting: Make a bus schedule. The bus can go as many times per hour. The user selects a stop and then every hour in a separate textView indicates the minute in which he comes to a stop.
If it matters: CardView is displayed in RecyclerView. All the data I have in the database, if this is important, then in Realm.
Link to the repository code: github.com/elsemTim/android-kotlin-bus_schedule
