Recyclerview Notifydatachange For only one item - android-recyclerview

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)).

Related

Spinner on clicking an item in DetailsList

How do I show a spinner in a DetailsList? For instance, let's say I have the following items in a DetailsList:
list of items
On clicking the item with the name 'AdipiscingUt.onetoc', show a spinner on the rightmost side of that item (next to 125 KB). Please let me know if you have any suggestions on the same.
Thanks!
You can use selection attribute in <DetailsList> component to catch the selection events. Then create extra column with hidden spinner and display it via selection event.
At least I had the experience when I needed to display the icon status according to each item. I added unique id per each item (using onRender method for columns attribute in <DetailsList>) and use it for identification.

Understanding 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.

Navigate to item 3 from item 1 in Panorama View

I have a panorama app and I want navigate to item 3 from item 1, When the user clicks a button at item 1 panorama but I don't know how to do this. I have searched but nothing.
I am using Long list selector to write the contents in the List.
How can i do This ?
this may help :
writing extra words to fill up thirty characters, i really dont need to write anything
http://blogs.msdn.com/b/aschapiro/archive/2012/07/21/navigating-directly-to-a-specific-screen-inside-a-panorama-or-pivot-page.aspx

Recreated active item doesn't get added to any container

I've encountered this in a couple spots in my app:
Let's assume I have 3 items in a carousel. I'm viewing item #2. I need to reload that carousel, so I do the following operations:
Ext.getCmp('carousel_name').removeAll();
var new_objects = (bunch of code that recreates the carousel's objects again, with the same IDs; this is the same code that was used to create the objects the first time, so it is likely not the issue)
Ext.getCmp('carousel_name').add(new_objects);
In the carousel object items list (Ext.getCmp('carousel_name').getItems()), all three items exist. However, only #1 and #3 (the ones which weren't the active item prior to the carousel reload) actually appear. #2 presents a blank white screen, and in the HTML nothing exists except for the item shell markup (no code that I've written shows up). If I do Ext.getCmp('carousel_item_2').show();, the item does appear, but is full-screen, and I get the error:
[DEPRECATE][Ext.Panel#show] Call show() on a component that doesn't currently belong to any container. Please add it to the the Viewport first, i.e: Ext.Viewport.add(component);
When I try to manually add that item to either the Viewport or the carousel, nothing is fixed.
I've tried inserting a dummy item in-between removal and reinsertion of new items, that doesn't work. Nor does hiding the entire Viewport before doing any of this and showing it afterwards. Nor does using setItems() rather than add(). Nor does doing Ext.getCmp('exercises_carousel').each(function(item){ item.destroy(); }) rather than removeAll(true)
I don't believe the issue is the code snippet that re-creates the new items, since it's the same code that's used to create the items the first time, and there are no issues on the first creation.
Pretty stumped here.
EDIT: I've found that if, when I get to the end of the carousel, if I add a empty item after the last item in the carousel, I don't get the blank item at N-2. No clue why this is the case. Still not a real solution, it's a hack.
Assuming there are no problems in your code snippet to re-populate new items in your carousel, then the only problem is because of this issue (I'm not sure whether it's a bug in Sencha Touch 2.1 or not but it does exist): when you call yourCarousel.removeAll() and add some new items again, your carousel will NOT set proper active item.
I've seen a similar problem and I added this after adding new items, which works:
carousel.setActiveItem(0);
Alright, this is a hack, so if anyone has a legitimate solution, that would be awesome. But the hack does work, so here it is:
Add an empty item in the carousel
Set active item to the new empty carousel item
Destroy all carousel items
Recreate (and re-add) all of the items
In code:
Ext.getCmp('carousel_name').add({});
Ext.getCmp('carousel_name').setActiveItem(Ext.getCmp('carousel_name').getMaxItemIndex());
Ext.getCmp('carousel_name').removeAll(true);
var new_objects = (bunch of code that recreates the carousel's objects again, with the same IDs)
Ext.getCmp('carousel_name').add(new_objects);
EDIT: As it turns out, this for some reason works 90% of the time; for some unknown reason 10% of the time it still doesn't get inserted. The only way to guarantee that all items get inserted correctly is to clear the entire viewport (Ext.Viewport.removeAll(true)), recreate all of the original items in the viewport, and reinsert them. I'd rather not have to do this every time an item doesn't get inserted.

Using grid events

Would anyone let me know how to refresh a grid depending on your selection from another grid. I'm looking at the example at
http://archive.dojotoolkit.org/nightly/checkout/dojox/data/demos/demo_QueryReadStore_grid.html
Is there is any way that the second grid can be updated once you click on any row in the first one. For example Assume that the first table has only the state names and the second one has the capitals. When I click on the State on the first table I only want to see the capital for that state at the second grid.
Please let me know if you have an answer for me.
Thanks,
I would do it this way, using refresh grid to change the store, and the layout of the other grid if necessary using the text value.
grid.onCellClick = function(e) {
refreshGrid(e.cellNode.innerHTML);
};