What is ListView?
ListViews are common in UI frameworks and are one of the most popular UI widgets. ListView is used to group several items in an array and display them in a scrollable list and the list can be scrolled vertically and horizontally. Here we are discussing two types of a listview with detailed examples and explanations.
1. Static ListView
If you have a shortlist of items and the value of items and they are not changing in the future and static, then you can use the default ListView constructor to make it. Let's take an example in which we are defining the names of the days.
In Listview we have ListTile widget which we can use as same as text widget in that we are showing the name of days and this is static so we have to define the length of the list for that we are using itemcount property.
Default list view gives a scroll direction verticle if you want horizontal listview then you need to add property scroll direction is horizontal.
2. ListVIew.builder
Static ListView is good for a shortlist but not for a long list. You can make a dynamically created ListView by using the ListView.builder() constructor. Dynamic ListView mainly uses when there are no pre-defined numbers of data and also if it will change as per adding the new data.
In Android, they have RecyclerView that extends from the basic ListView widget with new features and is easy to use. same as that we can use ListView.builder() and also notify data same as RecyclerView.
Comments
Post a Comment