Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
btpoole
Level 7

Refresh Grid View

Maybe missing something. Is there a way to refresh or update a markupgrid without calling the scene again. For instance I have a markupgrid with contents set and displaying on screen.  When a particular event occurs, the content node of the markupgrid is changed. Other than calling the scene, is there a way to reflect the content change in the markupgrid? 

The component xml file has the field. This is basically a copy from the sdk for markupgrid.
<field id="itemContent" type="node" onChange="itemContentChanged" />

I have an observerfield that triggers correctly and resets the content. I then reset the markupgrid content to the content but the markupgrid on the screen doesn't change. Something like

After content node has been changed I have the following in a function. I know the content is changed, I have checked this.
function refreshGrid()
m.myMarkupGrid = m.top.findNode("myMarkupGrid")
m.myMarkupGrid.content= m.global.posterx.shows
m.myMarkupGrid.SetFocus(true)
end function

I can get it to work if I call my main scene again, which makes sense but that's not what I need to do.  Calling the main scene again destroys everything and resets all elements. Thought there might be a refresh or redraw.
Thanks
0 Kudos
12 Replies
joetesta
Level 10

Re: Refresh Grid View

I think the proper way to do this is to create a new markupgrid node and replace the existing node from above, by assigning the new node to an observed node field that the parent will see and "replacechild" with the new node.

maybe something like 
function refreshGrid()
 newMarkupGrid = CreateObject("myMarkupGrid")
 newMarkupGrid.content= m.global.posterx.shows
 ' skipping the step here of assigning to a field that the parent observes, pseudo code'
 m.parent.replaceChild(newMarkupgrid, index)
end function


you'll need to first find and set the right m.parent and index values for this to work.
aspiring
0 Kudos
btpoole
Level 7

Re: Refresh Grid View

Thanks joetesta, I'll give this a shot.
0 Kudos
btpoole
Level 7

Re: Refresh Grid View

"joetesta" wrote:
I think the proper way to do this is to create a new markupgrid node and replace the existing node from above, by assigning the new node to an observed node field that the parent will see and "replacechild" with the new node.

maybe something like 
function refreshGrid()
 newMarkupGrid = CreateObject("myMarkupGrid")
 newMarkupGrid.content= m.global.posterx.shows
 ' skipping the step here of assigning to a field that the parent observes, pseudo code'
 m.parent.replaceChild(newMarkupgrid, index)
end function


you'll need to first find and set the right m.parent and index values for this to work.

Let me see if I understand. In order to update the existing grid, I first create a second component called newMarkupGrid in this case. I set the content of new component to my updated content (m.global.posterx.shows). I then have to find the parent of the grid and replace that grid with the new grid (along with it's content) at the appropriate index that the original grid is located. Ok, if this is correct I understand. Now, I am not sure how to get the parent or index. I know the grid is a child of my "HomeScene" which is the main scene of the app that is called. But I also have a busy spinner scene that is running prior to the HomeScene, so little lost on which is parent.
0 Kudos
joetesta
Level 10

Re: Refresh Grid View

"Now, I am not sure how to get the parent or index."

hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top; 


for i = 0 to m.top.getChildCount()-1
  child = m.top.getChild(i)
  if child.id = "myMarkupGrid"
    index = i
    exit for
  end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)

that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)
aspiring
0 Kudos
btpoole
Level 7

Re: Refresh Grid View

"joetesta" wrote:
"Now, I am not sure how to get the parent or index."

hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top; 


for i = 0 to m.top.getChildCount()-1
  child = m.top.getChild(i)
  if child.id = "myMarkupGrid"
    index = i
    exit for
  end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)

that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)


Thanks again joetesta, this example along with your previous info helped greatly.
0 Kudos
btpoole
Level 7

Re: Refresh Grid View

"btpoole" wrote:
"joetesta" wrote:
"Now, I am not sure how to get the parent or index."

hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top; 


for i = 0 to m.top.getChildCount()-1
  child = m.top.getChild(i)
  if child.id = "myMarkupGrid"
    index = i
    exit for
  end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)

that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)


Thanks again joetesta, this example along with your previous info helped greatly.  I would think there would have been a way to refresh, update  or redraw, would have never thought you would have to replace one node with another. I guess as long as it work. Thanks a million.
0 Kudos
btpoole
Level 7

Re: Refresh Grid View

"btpoole" wrote:
"btpoole" wrote:
"joetesta" wrote:
"Now, I am not sure how to get the parent or index."

hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top; 


for i = 0 to m.top.getChildCount()-1
  child = m.top.getChild(i)
  if child.id = "myMarkupGrid"
    index = i
    exit for
  end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)

that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)


Thanks again joetesta, this example along with your previous info helped greatly.  I would think there would have been a way to refresh, update  or redraw, would have never thought you would have to replace one node with another. I guess as long as it work. Thanks a million.


Something odd is happening to my children of the m.top.  I actually have (2) grids. If I run the for loop above and print the child.id I can see each child of the parent. Once it finds the "myMarkupGrid" and exits the loop with the correct index and does the replace, all seems fine. Except that if I run the loop again to print the child.id right after the replace, the child just before the replace index is gone. For example, on the first run "myMarkupGrid1" is index 14 and "myMarkupGrid" is index 15. The loop finds the "myMarkupGrid" at 15 and does the replace. When the loop is ran a second time, the "myMarkupGrid1" is no longer present and the "myMarkupGrid" is moved to index 14.  I noticed this when the "myMarkupGrid1" started disappearing from the screen after the function has ran. I can't imagine a replace would remove a child from the parent and reindex the remaining. Is this a bug? I have tested this several times, which ever replace I do first, the child just before just after the found child is taken out of the list of children. 
0 Kudos
joetesta
Level 10

Re: Refresh Grid View

that's really strange, doesn't seem like we're replacing the wrong index.  Any chance that second grid is a child of the first?
aspiring
0 Kudos
btpoole
Level 7

Re: Refresh Grid View

"joetesta" wrote:
that's really strange, doesn't seem like we're replacing the wrong index.  Any chance that second grid is a child of the first?

Well I thought maybe also, but both are from the m.top. I can run the loop twice and rem out the replace, all children show up.  I am doing something a little different from your example
Where you had 
newmarkupGrid= createobject("myMarkupGrid")

I done this
newmarkupGrid= myMarkupGrid

Nor sure if this is making it go wrong or not. It does return true for the replace but not sure why it removes the child before and after the replaced child, and even reindexed the children. Going to try something else and see if I can track it down. Just thought maybe the replace had a glitch.
0 Kudos