UI freezes while adding many views programmatically

230
April 05, 2017, at 10:01 PM

i have views with hundreds layouts(Linears with TextViews), basically it's like list with data. my presenter after quering database(sqlbrite, rxjava, its asynchronous) calling method on view which simply create linear with textviews and adds it to some other Linear(its parent for every added view)

with 100+ data on my older phone there is a freeze. how can i reduce it? i cant add views on other thread than UI of course.

Answer 1
  1. First thing you need to use a recycler view for list of views. and ofcoarse you can use 100 different types of views with ViewTypes of recycler view
  2. Second if you insist not to use recycler view then you may better use AsyncTask for adding views at least. Because in some methods of AsyncTask you can access the UI thread and can add elements.
  3. Third possibility is with event bus. you will add a method to the fragment/activity and register it with event bus. make it run in background from the tag(java tags). and call it from background thread for adding items(views)

Hope some of it solve your problem :) if not get back to me with more explanation of the question.

P.S EventBus is a library work almost the same as BroadcastReceivers but it has more features and its more efficient as well.

READ ALSO
Unable to show current location in webview in android

Unable to show current location in webview in android

The project is developed with php in server side and the location credentials are stored in cookie sessions of the device webview from server itselfBut the stored locations are not showing

236
Android Wake up app on bluetooth keyboard key pressed

Android Wake up app on bluetooth keyboard key pressed

I'm trying to develop an app that recognizes when a paired bluetooth keyboard's key is pressed and wakes up the app with certain actionThe bluetooth device in particular is the Selfie Remote Shutter (this one, no ads intended: http://www

320
Why doesn't Apache Cordova support databases bigger than 50 MB?

Why doesn't Apache Cordova support databases bigger than 50 MB?

The offical Apache Cordova documentation describes 3 ways of storing data:

191