I was advised to use RecyclerView for lists that pull data from the network. And what about lists that use buttons or text fields? Does it make sense to shove Recycler everywhere? And if not, what is better to use in simple cases?
2 answers
RecyclerView should be used in cases where the number of list items is not known in advance , and the list items are added dynamically during the program operation.
And if, for example, you need to scroll through the list with several buttons, the number of which is known in advance , then in this case, a sensible solution would be to use ScrollView .
- And what about the list of buttons that are horizontally? Just hang a scroll on them and that's it? - Taras Zhupnik
- one@TarasZhupnik, I don’t really understand what you are talking about. If you have a predetermined number of buttons, then you can wrap them, for example, in
LinearLayout, which, in turn, will be a descendant ofScrollView. - post_zeew 10:39 pm - Thanks for the advice. This interested me - Taras Zhupnik
- oneWhat is
ScrollView? katso correctly wrote - if the number of views is known in advance, but there are a lot of them, can you imagine what kind of markup it will be? It is better to useListViewfor lists with a known length. As, to put listeners on all buttons - govnokod. And withListViewyou can put one and revive the whole thing. IMHO, for lists with an unknown length would be suitable andListView. - Flippy - oneYou need to use
ListView, because choosing aScrollViewwill kill your speed. AboutRecyclerView- agree - GuardFromUA
|
Definitely worth using RecycleView + CardView, you can add buttons and texts to each element without problems. As an example, here’s the markup for each list item:
<android.support.v7.widget.CardView android:id="@+id/cv" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout style="@style/Wide" android:padding="16dp" android:background="#FFFFFF" > <ImageView android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/imageTask" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginRight="16dp" /> <TextView style="@style/Wrap" android:id="@+id/contentTask" android:layout_toRightOf="@+id/imageView" android:layout_marginLeft="40dp" android:layout_alignParentTop="true" android:textSize="14sp" android:textColor="#000000" /> <LinearLayout android:id="@+id/lin1" style="@style/Full" android:layout_marginTop="20dp" android:orientation="vertical"> <TextView android:id="@+id/createData" style="@style/Wrap" android:layout_alignParentTop="true" android:layout_marginLeft="40dp" android:textColor="#000000" android:textSize="14sp" /> <Button android:id="@+id/completed" style="@style/Wrap" android:textSize="10sp" android:text="Completed" /> </LinearLayout> </RelativeLayout> </android.support.v7.widget.CardView> And so it will look like markup activation with a list
<android.support.v7.widget.RecyclerView android:id="@+id/recycleView" style="@style/Full"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" style="@style/Fab" android:src="@drawable/add_icon" /> |