Android - Loading multiple text files into a RecyclerView - android

I'm writing a notetaking application for Android, and I have a RecyclerView to display a grid of all the notes. Each note has a respective class called Note.
The note class knows/has:
The filename (Notes title)
The file path for the note
A loading method that reads and returns the text inside the file
The recyclerview reads from a ArrayList of Note. The list is populated by a scan of files in the App's note directory, and a Note object is created for each file. I'm trying to find the best way to load the text into the recyclerview, which displays a preview of the notes. I'm wondering if theres a best way, or least stupid way to do this. The ways I can think of doing this are:
Load every note's content at once during the initial scan and save it as a string in the note class in RAM, the downside being very high RAM usage with alot of notes and text.
Load the note's text in the Recylerview's onBindViewHolder method, but I'm worried if the user is scrolling through notes very fast, and a ViewHolder and its note are unbound before the text is loaded, there could be possible issues here.
Load each note's text in a threadpool, increases performance but same issue as above.
Is there a best way to do this, or a recommended/standard way to handle alot of files loading dynamically into a recyclerview?

Start off with the first one, then optimise as needed. If theyre just text files, they probably wont take up much memory. If you find they do take up too much memory or take too long to load you can look at strategies to fix that, but dont waste time optimising something before you know its a problem

How did you tacke The problem?
I am also making a same Kind of APP, I thing The best option is The second (loading filé contents on bindViewHolder) in an async maner (using asynctask, for example), it's the same BASIC ideia of imagem loaders like Picasso or Glide, you call them on Bind ViewHolder.
If having bad performance you could wrap The async call alongside a caching strategy.

Related

RecyclerView with different viewtypes for editing big data object

I've solved this previously with nested layouts in a scrollview.
But its pretty bad performance-wise and a pain in the ass to add anything new/update the functionality.
A quick mockup:
Basically there's a few tabs, all of them have different category of settings, since this is just an app to configure a Windows/macOS application.
I'm getting a JSON string from my server, it's pretty big, roughly 3k lines, and deserialize it to a big object. Not sure yet if I want to have local SQLite database or just keep editing the object in memory, serialize it, and post it back to the server when I'm finished editing.
How the hell would one approach this? The view type depends on the data type, but sometimes I'll use a spinner to limit the range/items one can chose.
I don't think there's a depedency for marking the fields in the model, so the recyclerview would know what view to use?

Is it normal to use AsynTask in viewHolder in CustomAdapter

I have custom adapter (one image, 2 text fields), and I need to check image inside viewHolder. When image is already exist, show that image in ImageView and when image isn't exist, I need to check connection, if all good, show progressbar, download image, and show it, and if all bad then show default image. Sorry for my English.
No you should not implement a Async Task inside ViewHolder bcoz you do not know how much time it will take to load images and the user will be pissed at waiting for the listview to come up.
There are lot of tutorials out there you should use lazy loading for images if you are using URLS for images if there are not much images then you can store it in database or in a file and show any time in the listview
Hope it Helps :)
I've seen many people using, it is normal for small operations.
but it can't be used for tasks which take time - as the user experience is affected by lagging.
for small operations you can use it.

Android dynamically creating UI v. ListView

I have an android app that I'm developing using Xamarin. The app contacts the server and, via web service (SOAP), receives a list of objects. Currently, in my axml file I have just linear layout (ll) within scrollview tags and nothing else. In the code, I loop through the collection and new up the elements that I want and attach it to a layout. Once I'm done with each record, I attach (i.e.AddView) to the master layout (ll). Everything works.
I have a couple of concerns and I appreciate some feedback on it.
1) Each object in the list contains an URL to an image online. Currently, for each object, my process downloads the picture individually. Would ListView give me any advantage of reusing (caching , etc.) an already downloaded picture even though other attributes of the objects are different? Will there be any gain in terms of network utilization if I switch to ListView?
2) Is drawing elements by hand (like I'm doing) an acceptable best-practice?
Thanks all.
Definitely use a ListView. There is a great article here by Lucas Rocha that outlines exactly why ListViews are beneficial and how to make them perform even better. To give you a few examples, ListViews minimize the number of view inflations you do, and they only create the list items currently visible on the screen or about to become visible on the screen.
This is a huge improvement from your approach, since your current method would load every element in the list before presenting the activity to the user. Therefore, drawing elements by hand like you're currently doing is definitely not best-practice.
Also, for displaying images from URLs in your Xamarin app, I highly recommend that you use the Xamarin component UrlImageViewHelper. Despite being incredibly easy to implement in your app, it will improve performance drastically since it takes care of image caching and async image loading.

Keep the images downloaded in the listview during scrolling

I'm developing my first app and have been reading a LOT here.
I've been trying to find a solution for the following issue for over a week with no luck.
I have an Adapter that extends ArrayAdapter to show image and 3 lines of text in each row.
Inside the getView I assign relevant information for the TextViews and use ImageLoader class to download image and assign it to the ImageView.
Everything works great! I have 4.5 rows visible on my screen (out of total of 20). When I scroll down for the first time the images continue to download and be assigned in right order to the list.
BUT when I scroll back the list looses all the images and start redrawing them again (0.5-1 sec per image) in correct order. From what I've been reading it's the standard list performance but I want to change it.
I want that, once the image was downloaded, it will be "sticked" to the list for the whole session of the current window. Just like in Contacts list or in the Market. It is only 20 images (6-9kb each).
Hope I managed to explain myself.
you need to cache each image after download it, and each time the adapter need it check if its already downloaded get it from cache (disk or memory) otherwise download it.
at first i recommended you to read this tutorial from android dev site http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
or use an external lib like this one https://github.com/koush/UrlImageViewHelper
The problem here is that the ArrayAdapter is reusing the list view rows as you scroll, so as you scroll down, the top row will be reused and inserted at the bottom of the list (for performance reasons).
Your best bet here is to try to cache the images locally on your device to avoid calling the ImageLoader every time.
One pretty good library that solves this problem is ignition. It's open source and available here: https://github.com/kaeppler/ignition
Take a look at RemoteImageView for a good example of the caching mechanism.

Android: Internal Linkify does not work properly, and text, images flicker inside ListView

I enabled the Linkify property of a textview as follows:
txtbox.setAutoLinkMask(Linkify.WEB_URLS);
But, when there are URLs like bit.ly are present (which is very common nowadays in messages like tweets), it doesn't display them properly. The problem is "sometimes" it succeeds and sometimes it fails... The other problem is, if this TextView is part of a custom view for a ListView, then until I actually scroll the list somehow none of the URLs get linkified...
The other problem is, if there is an image inside a ListView, when I scroll through the list, I can see a different image load before it loads the actual image. I assume this is happening due the recycling of views, but is there any workaround for this?
But, when there are URLs like bit.ly
are present (which is very common
nowadays in messages like tweets), it
doesn't display them properly.
You don't really explain what "doesn't display them properly" means, so it is difficult to provide advice there. All I can do is point you to a project that uses android:autoLink="all", and I haven't received comments from students or readers that certain URLs aren't working.
If you succeeds/fails reference is with respect to whether or not it gets turned into a link, there may be a bug in the Linkify pattern matching algorithm. Jot down several links that fail and see if you can find a common pattern (e.g., has some funky punctuation).
if there is an image inside a
ListView, when I scroll through the
list, I can see a different image load
before it loads the actual image. I
assume this is happening due the
recycling of views, but is there any
workaround for this?
If you are populating your images immediately, I'm not aware that you will get this effect. I see this when I am loading the images based on work in a background thread (e.g., downloading the images to a cache, then updating the ImageView). One thing to do in that case is to replace the image with a placeholder in your adapter until the real image is ready.

Categories

Resources