Lesson 3 - RecyclerView Flashcards

Efficient scrolling; common design patterns.

1
Q

RecyclerView is?

A

Efficient way to view, scroll + interact with data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Problems with scrollView

A

resource intensive; while could contain all of cells at once, uses a lot of memory + lots of upfront loading+setup. So, RecyclerView.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

RecyclerView high-level works how?

A

what’s visible, plus some of what’s not (those closely off screen) in a queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Modules around RecyclerView

A

Layout Manager, RecyclerView, Adapter+ViewHolder, Data Source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Adapter

A

provide views when needed to RecyclerView
also binds data from some Datasource to the view
sends views to RecyclerView in ViewHolder objects;
(ie view-provider and databinder)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ViewHolder object

A

contains a reference to the root view object for the item
used to cache view object for the layout to make it less resource intensive
findViewById therefore called only when inflating views, and not when binding views to data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Layout Manager

A

tells RecyclerView how to layout all its views

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

steps to RecyclerView

A
  1. add dependency
  2. create RecyclerView in Layout
  3. create item list layout and ViewHolder
  4. add RecyclerView adapter
  5. add LayoutManager, connect everything
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

sp vs dp

A

sp scales with user preferences

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

use of ViewHolder

A

extend base RecyclerView.ViewHolder,
add property for view,
populate view property in constructor (parameter type View cast to specific type of property’s view),
bind method to set data for view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

String from int Java

A

String.valueOf()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Adapter does; 3 overrides

A
  1. create new items
  2. populates items with data
  3. returns information

overrides:
1. onCreateViewHolder; called when recyclerview instantiates new Viewholder instance
2. onBindViewHolder; called when Recyclerview wants to populate the view with data from our model, so that the user can see it, effectively binding it to datasource
3. getitemcount, returns number of items in data source
also inflates view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is inflation?

A

“Inflation” is a term that refers to parsing XML and turning it into UI-oriented data structures. You can inflate a view hierarchy, a menu structure, and other types of resources. Often this is done behind the scenes by the framework (when you call setContentView(R.layout.main), for instance). A typical case when you explicitly inflate something yourself is when creating menus, as described in the guide subject Creating Menus.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

code to inflate for MyViewHolder

A

public NumberViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
Context context = viewGroup.getContext();
int layoutIdForListItem = R.layout.number_list_item;
LayoutInflater inflater = LayoutInflater.from(context);
boolean shouldAttachToParentImmediately = false;

    // TODO (7) Override onBindViewHolder
    // TODO (8) Within onBindViewHolder, call holder.bind and pass in the position
        View view = inflater.inflate(layoutIdForListItem, viewGroup, shouldAttachToParentImmediately);
        NumberViewHolder viewHolder = new NumberViewHolder(view);
    return viewHolder;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

viewholder

A

determines how an individual entry is displayed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

layout manager

A

determines how the collection of items is displayed

17
Q

layout manager types

A

linear, grid, staggered grid

18
Q

using recycler view and adapter

A

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

        // TODO (4) Use findViewById to store a reference to the RecyclerView in mNumbersList
        mNumbersList = (RecyclerView) findViewById(R.id.rv_numbers);
        // TODO (5) Create a LinearLayoutManager variable called layoutManager
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        // TODO (6) Use setLayoutManager on mNumbersList with the LinearLayoutManager we created above
        mNumbersList.setLayoutManager(layoutManager);
        // TODO (7) Use setHasFixedSize(true) to designate that the contents of the RecyclerView won't change an item's size
        mNumbersList.setHasFixedSize(true);
        // TODO (8) Store a new GreenAdapter in mAdapter and pass it NUM_LIST_ITEMS
        mAdapter = new GreenAdapter(NUM_LIST_ITEMS);
        // TODO (9) Set the GreenAdapter you created on mNumbersList
        mNumbersList.setAdapter(mAdapter);
    }
}
19
Q

adding interface for onClick listener

A
  1. declare interface as part of adapter class
  2. add member of onClickListener that adopts interface
  3. in constructor, accept an onClickListener parameter and set to member
  4. in adapter’s ViewHolder, implement View.onClickListener (pre-existing interface)
  5. in adapter’s ViewHolder, when given a view, view.setOnClickListener to this
  6. override the onClick this gives us, by getting current adapter position and returning onClick
20
Q

adapter idea

A

views (ListView, GridView, RecyclerView) need specific information to display the data. This specific information they need is specified by the interface Adapter. An adapter adopts the Adapter interface, and is hooked up to its data source. Adapter can then specify the the view what the view needs, by hooking up the adapter and the view.