Skip to content

Make use of standard RecyclerView Holder optimizations. #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2016

Conversation

CodingDoug
Copy link
Contributor

An important optimization that RecyclerView offers is the ability to cache the results of (potentially expensive) calls to findViewById() inside a ViewHolder so that they don't have to be repeated every time data is bound to a recycled view.

left_arrow.setVisibility(View.GONE);
right_arrow.setVisibility(View.VISIBLE);
messageContainer.setGravity(Gravity.END);
color = ContextCompat.getColor(itemView.getContext(), R.color.material_green_300);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're feeling cache-y, might as well cache these two colors on ViewHolder creation (or even at a higher level)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considered that, but those could actually theoretically change when the configuration changes as well. If we want to assume they don't, then they're cachable as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a very simple sample app let's assume they don't.

@samtstern
Copy link
Contributor

LGTM, made one comment for an additional improvement while I have you here.

@samtstern samtstern merged commit 2636028 into firebase:master Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants