Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm doing an app where I have a RecyclerView( https://github.com/thoughtbot/expandable-recycler-view ) with hundreds of elements and Log prints this:

2022-02-23 17:01:21.340 D/RecyclerViewAdapterUpdateExpandable: >>Toggle Tag Tutte le carte
2022-02-23 17:01:21.992 D/View: [ANR Warning]onMeasure time too long, this =androidx.recyclerview.widget.RecyclerView{51f7538 VFED..... .F....ID 0,99-720,1257 #7f0a017e app:id/recycler_view_list}time =627 ms
2022-02-23 17:01:21.992 D/View: [ANR Warning]onMeasure time too long, this =androidx.constraintlayout.widget.ConstraintLayout{342a04c V.E...... ......ID 0,0-720,1258}time =628 ms
2022-02-23 17:01:21.993 D/View: [ANR Warning]onMeasure time too long, this =androidx.constraintlayout.widget.ConstraintLayout{e45720f V.E...... ......ID 0,-1-720,1257 #7f0a00cd app:id/fragment_container}time =629 ms
2022-02-23 17:01:21.996 D/View: [ANR Warning]onMeasure time too long, this =androidx.constraintlayout.widget.ConstraintLayout{c686b6e V.E...... ......ID 0,0-720,1353}time =632 ms
2022-02-23 17:01:21.996 D/View: [ANR Warning]onMeasure time too long, this =androidx.appcompat.widget.ContentFrameLayout{1a3af70 V.E...... ......ID 0,0-720,1353 #1020002 android:id/content}time =632 ms
2022-02-23 17:01:21.996 D/View: [ANR Warning]onMeasure time too long, this =androidx.appcompat.widget.FitWindowsLinearLayout{25104ed V.E...... ......ID 0,0-720,1353 #7f0a0037 app:id/action_bar_root}time =632 ms
2022-02-23 17:01:21.996 D/View: [ANR Warning]onMeasure time too long, this =android.widget.FrameLayout{7092eb1 V.E...... ......ID 0,91-720,1444}time =632 ms
2022-02-23 17:01:21.996 D/View: [ANR Warning]onMeasure time too long, this =android.widget.LinearLayout{9d3323b V.E...... ......ID 0,0-720,1444}time =632 ms
2022-02-23 17:01:21.997 D/View: [ANR Warning]onMeasure time too long, this =DecorView@1af831f[MainActivity]time =632 ms
2022-02-23 17:01:22.045 I/Choreographer: Skipped 39 frames!  The application may be doing too much work on its main thread.

Are there any common practices to improve the performance? I've tried to empty constructor of the ViewHolder and onBind() methods but the time is about the same, so I think the time depends only on the number of items.

If onMeasure is creating ViewHolders and calling onBind, that itself is probably a problem. Especially if it's doing it for every item, that's a complete violation of how a recycler view should work (if an item isn't on screen it shouldn't even be fetched, much less bound). – Gabe Sechan Feb 23, 2022 at 16:15 So the problem is that the Recycler of the library I'm using is not good? I never call onMeasure() in my code. – Daniele Scalco Feb 23, 2022 at 16:29 onMeasure is called whenever a view is resized (including the first time it's sized) and is called by the system. – Gabe Sechan Feb 23, 2022 at 16:51

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.