Understanding RecyclerView - android-recyclerview

Let's assume that we have a RecyclerView with 100 rows. Every row contains a Spinner with values from 1-5 (default of 1).
I scroll down to item row #100, change it's value to 5 and then scroll back up to row #1, my questions is:
When i scroll down again to row #100, will i see the Spinner with value of 5 that i have selected earlier? or the default value of 1 since the RecyclerView will recycle items for re-use (performance boost) and not hold all 100 rows in memory.
Would love to get a good explanation on how this works.

Like you said, the RecyclerView will not hold the 100 rows in memory, hence the name RecyclerView. How many views of the same layout the RecyclerView will hold depends on how many of them fit on the screen.
When you change item #100's value to 5, you are altering one of the recycled views. Now, until you modify that ViewHolder (typically done in onBindViewHolder()), the view will stay the same, which means that that specific ViewHolder will still have 5 as its Spinner value; at any position you are in the list, not necessarily if you scroll down to item at #100, you will see one item with the Spinner value of 5.

Basicly, RecycleView is just that, a View.
So if you scroll to #100 and set spinner to 5, you need to save your selection to the underlying data array.
That way when you scroll to #1 and back to #100, when onBindViewHolder() is called correct value will be loaded and spinner in #100 will show 5.
RecycleView only optimizes UI, as Ari mentioned.

Related

ngx datatable vertical scroll bar does not come back to start of page if there there are more records than defined page size

Pre condition -
Have pagination, searchTerm, and vertical scrolling implemented and works fine.
records to show per page = 25
Steps to reproduce
User has searched for say 'batMan0' in the list of 100 files. Let's say names are from batMan001.txt to batMan099.txt.
User then scrolls to say page 2 by grabbing scrollbar and pulling it down. Now total number of files on the table is = 50 ( batMan001.txt to batMan050.txt)
Now user refines the search term to 'batMa', (so that search result increases). Once the search is finished, pageNumber resets to 0. This is OK.
The Problem -
Problem is with scroll bar. It does not come back to first row of the table and stays at the same place where user has left on table last time. And because of this, the rows are not visible and user has to scroll up to see the table rows.
How can I fix this issue i.e. bring back the scroll bar to first position.
Any help would be highly appreciated.

Recyclerview Notifydatachange For only one item

I have a Recyclerview with a long list of items. One Item have a TextView, this TextView need change every 0.5 seconds, so i need refresh. All my code works perflecly but If I refresh all my items (notifyDataChange), its to slow. So I need refresh only this item for a good perfomance of my app. Its possible?
AdaptadorRecyclerView.notifyDataSetChanged();
Use adapter.notifyItemChanged(int position, Object payload). You can mention the TextView's position and value with payload parameter. If you want to learn more about it please refer [this link](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyItemChanged(int, java.lang.Object)).

Loading items in Combobox

I am working on a project and the problem that I have is; the items of my combobox are being loaded from the database table(one field); the table has more than 1000 records:
how can I load these records(one field) as items by giving a limit of 50 while allowing the user who wants to see all of the records through the combobox to see them but still by a group of 50?
which event can be the best for loading items to the combobox? textchanged, click....
I was thinking to use the vertical scroll bar so that when the user is at the end of the displayed items the next 50 will be loaded and if he is on the first and scrolls up the previous 50 will be loaded:problems with this way of thinking are:
when the user typed some caracter from the word that he wanna select
from the items' list if it is not loaded yet from the DB he will be
obliged to type the whole word
I don't know which event is raised
when scroll bar of reaches the end or is at the beginning
Is there any other way to do that?

Data Grid View VB.net 2013 , How many rows and which are visible in window?

I have a datagridview control with 10 rows on my form window.
Now lets suppose the size of the datagridview in the form can only display 5 rows to user and user has to use vertical scroll bar to see the other 5 rows.
now my question is :
Is there any way to know which 5 rows are currently visible to the user according to the position of scroll bar.
Actually in my program currently i am updating the all the rows value one by one of that datagridview table continuously.
Now i want to only update the rows that are visible in the window. so how can i know what rows are visible according to scroll bar position.
Thanks in advance
The DataGridView control exposes a VerticalScrollingOffset property which can be used to determine how far the view is scrolled. If you know the height of each row in the DataGridView in pixels, you can then calculate which rows of the table are currently visible and refresh them.
The height of each row can be determined through the DataGridViewRow property Height. This defaults to the font height, plus 9 pixels - if you're using the same font size in all rows this should be consistent.
EDIT: Further digging through the documentation shows that each DataGridViewRow exposes a Displayed property that returns true when the row is visible on the user's screen. Checking that would be much easier!
MSDN on DataGridViewRow.Displayed property

how to change the background color of an item in a listbox when its string value is equal to something?

i have a listbox that contains the words "week1", "week2", ..... all the way up to "week52" and when i select a week from the listbox it will retrieve a value from a mysql database that will represent a progress bar value. my progress bar has a range of 0-120 and i would like to have all the weeks that have values higher than 100 to be highlighted or marked somehow, in the listbox. so my question is, "is there a way to set the background color of certain weeks in the listbox to orange based on the value that they represent on the database?
for example for "week1", the value is 114, so when the listbox loads, i want the background color of the item "week1" in the list to be orange (indicating that it's current value is higher than 100)? i know that this requires me to implement a user defined drawing function for the listbox items but i dont know where i would even start. i would like this to be somewhat automatic so that it checks the values and changes the background colors of any value higher than 100, instead of me specifying a name of the item.
Thanks in advance!
I don't believe you can do this with a Listbox (at least not without creating your own implementation/subclassing/overriding/whatever of a Listbox).
Pretty sure you could do it with a ListView (in Detail mode), though, if that helps.