Basic App Flashcards
What is needed in Adapter class?
Extend adapter onCreateViewHolder onBindViewHolder getItemCount new layout for views for items
What is the function signature for onCreateViewHolder?
public ViewHolder onCreateViewHolder(ViewGroup, viewType)
What does onCreateViewHolder do?
1) gets the id from the layout xml item
2) creates an inflator
3) creates a view from inflator
4) Creates new viewHolder by passing view into viewHolder constructor
What is the function signature for onBindViewHolder in the adaptor
public void onBindViewHolder(ViewHolder, position)
What does the adaptor constructor take?
number of items
What does the onBindViewHolder in the adapator do?
call viewHolder.bind
What is in the ViewHolder?
extends the RecyclerView.ViewHolder
gets the text view in the layout from constructor
contains the bind function to set the text of the listView
difference between view holder and layout manager
view holder: determines how an individual entry is displayed
layout manager: determines how the collection of items is displayed
3 types of layout managers
LinearLayoutManager
GridLayoutManager
StaggeredGridLayoutManager
Steps for Recycler View
Add dependency to gradle
Add Recycler view to .xml
description of onCreateViewHolder
gets called when each new ViewHolder is created; happens when the RecyclerView is laid out; Enough ViewHolders will be created to fill the screen and allow for scrolling
description of onBindViewHolder
called by RecyclerView to display the data at the specified position; update the contents of the ViewHolder to display the correct indices in the last for the particular position given
In Main Activity onCreate() to Hook up Layout Manager
1) setContentView(R.layout.activity)
2) get RecyclerView from xml id
3) create new layout manager
4) RecyclerView.setLayoutManager(layoutmanager)
5) Create new adapater
6) RecyclerView.setAdapter(adapter)
What does the adapter do?
Sends data to RecyclerView via View Holder
Provides new views
binds data with data source
onCreateOptionsMenu signature
public boolean onCreateOptionsMenu(Menu menu)