The document discusses RecyclerView and how it differs from other Android views like ListView and GridView. It provides details on:
1) RecyclerView recycles views as the user scrolls, improving performance for large data sets compared to other views.
2) Adapters for RecyclerView override different methods like onCreateViewHolder and onBindViewHolder to inflate views and populate them with data.
3) The ViewHolder class in RecyclerView is used to cache views and data associated with each list item to avoid re-finding views and improve performance of binding data.
The document discusses RecyclerView and how it differs from other Android views like ListView and GridView. It provides details on:
1) RecyclerView recycles views as the user scrolls, improving performance for large data sets compared to other views.
2) Adapters for RecyclerView override different methods like onCreateViewHolder and onBindViewHolder to inflate views and populate them with data.
3) The ViewHolder class in RecyclerView is used to cache views and data associated with each list item to avoid re-finding views and improve performance of binding data.
The document discusses RecyclerView and how it differs from other Android views like ListView and GridView. It provides details on:
1) RecyclerView recycles views as the user scrolls, improving performance for large data sets compared to other views.
2) Adapters for RecyclerView override different methods like onCreateViewHolder and onBindViewHolder to inflate views and populate them with data.
3) The ViewHolder class in RecyclerView is used to cache views and data associated with each list item to avoid re-finding views and improve performance of binding data.
Due-Date 27-04-2021 Program: BSCS Name: Abdullah Bin Afzaal Sap Id: 70066868
Answer the following statements
1. How do you write the difference between Customer Adapter and RecyclerView? Customer Adapter: You can also create custom adapter to display items as you want Layout-Inflater: There are two ways to create UI in android. One is a static way and another is dynamic or programmatically. Suppose we have a simple layout main.xml have one text view and one edit text. We can display this layout in static way by public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); A dynamic way of creating a view means the view is not mentioned in our main.xml but we want to show with this in run time. RecyclerView: Recycler View class is a modernized version of the List View and the Grid View classes, that supports the display of a collection of data. Recycler View makes it easy to efficiently display large sets of data. As the name implies, Recycler View recycles those individual elements. When an item scrolls off the screen. For example,
if a user scrolled down to a position where items 4 and 5 are visible;
items 1,2 and 3 would be cleared from the memory to reduce memory consumption. ✓ In Android 5.0 Lollipop, Android introduced RecyclerView widget. ✓ RecyclerView is flexible and efficient version of ListView. ✓ It is a container for rendering larger data set of views that can be recycled and scrolled very efficiently.
2. How Customer Adapter function getView() implemented in
RecyclerView()? Public View getView (int position, View convertView, ViewGrouparent) Get a View that display the data at the specified position in the data set. You can either create a View manually or inflate it from an XML layout file. When the View is inflated, the parent View (GridView, ListView ..) will apply default layout parameters unless you use LayoutInflater.inflate(int, android.view.ViewGroup, boolean) to specify a root view and to prevent attachment to the rool.
3. How inflater class inflate List items in Recycler View?
LayoutInflater creates View objects based on layouts defined in XML. It takes a xml layout file as input and converts it to View objects, in other words, Layoutinflater is a class that reads the xml appearance description and convert them into java based objects. 4. What is the purpose of recyclerAdapter.recyclerHolder onCreateViewHolder, onBindViewHolder? createViewHolder(ViewGroup parent, int viewType) This method calls onCreateViewHolder(ViewGroup, int) to create a new RecyclerView.ViewHolder and initializes some private fields to be used by RecyclerView. bindViewHolder(VH holder, int position) This method internally calls onBindViewHolder(ViewHolder, int) to update the RecyclerView.ViewHolder contents with the item at the given position and also sets up some private fields to be used by RecyclerView.
5. What is the purpose of RecylerView.ViewHolder class?
A ViewHolder describes an item view and metadata about its place within the RecyclerView. RecyclerView.Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive View.findViewById(int) results. While RecyclerView.LayoutParams belong to the RecyclerView.LayoutManager, ViewHolders belong to the adapter. Adapters should feel free to use their own custom ViewHolder implementations to store data that makes binding view contents easier. Implementations should assume that individual item views will hold strong references to ViewHolder objects and that RecyclerView instances may hold strong references to extra off-screen item views for caching purposes