Page 1 of 1
Dynamic Listviews
Posted: Wed Apr 21, 2021 11:06 pm
by davec
Hi everyone,
I have some code that allows for dynamic column creation in a listview, and this works fine on Windows, Mac, Linux etc.
However, it doesn't seem to work on Android (at least on a compiled app on Android, it might run under the player but haven't checked).
Does anyone have any idea why this doesn't do anything on Android?
Thanks,
Dave
Code: Select all
moai.DoMethod("mylistview", "initchange")
moai.DoMethod("mylistview", "remove", "listview1")
moai.DoMethod("mylistview", "exitchange", False)
moai.FreeObject("listview1")
moai.CreateObject(listviewXml$, "mylistview")
moai.DoMethod("mylistview", "initchange")
moai.DoMethod("mylistview", "append", "listview1")
moai.DoMethod("mylistview", "exitchange", False)
Re: Dynamic Listviews
Posted: Sat Apr 24, 2021 2:52 pm
by airsoftsoftwair
Could be a bug... can you post an
MCVE that I can try?
Re: Dynamic Listviews
Posted: Sun Apr 25, 2021 7:29 am
by davec
Try this...
Code: Select all
@REQUIRE "RapaGUI"
xmlColumnTemplate$ = [[<column title="tmpcol" icon="True" />]]
xmlHead$=[[<?xml version="1.0" encoding="iso-8859-1"?>
<application id="dynlistview">
<window id="win">
<vgroup>
<hgroup id="mylistview" frame="true">
<listview id="listview1" forcemode="dataview">
<column title="col0">
</column>]]
xmlTail$=[[ </listview>
</hgroup>
<hgroup>
<button id="add">Add column</button>
</hgroup>
</vgroup>
</window>
</application>]]
xml$ = xmlHead$ .. xmlTail$
Function p_EventFunc(msg)
Switch msg.action
Case "RapaGUI":
Switch msg.attribute
Case "Pressed":
If msg.id = "add"
count = count + 1
listviewXmlHead$ = [[<listview id="listview1" forcemode="dataview">]]
listviewXmlTail$=[[ </listview>]]
Local listviewXml$ = listviewXmlHead$
For Local i=0 To count-1
listviewXml$ = listviewXml$ .. ReplaceStr(xmlColumnTemplate$, "tmpcol",columnTitleArray[i]) .. "\n"
Next
listviewXml$ = listviewXml$ .. listviewXmlTail$
; Comment out below section for Android
moai.DoMethod("mylistview", "initchange")
moai.DoMethod("mylistview", "remove", "listview1")
moai.DoMethod("mylistview", "exitchange", False)
moai.FreeObject("listview1")
moai.CreateObject(listviewXml$, "mylistview")
moai.DoMethod("mylistview", "initchange")
moai.DoMethod("mylistview", "append", "listview1")
moai.DoMethod("mylistview", "exitchange", False)
; Comment out above section for Android
EndIf
EndSwitch
EndSwitch
EndFunction
;Maxes out at 4 then error but shows the issue
columnTitleArray= {"col1","col2","col3","col4"}
moai.CreateApp(xml$)
; listen to these events!
InstallEventHandler({RapaGUI = p_EventFunc})
; main loop!
Repeat
WaitEvent
Forever
airsoftsoftwair wrote: ↑Sat Apr 24, 2021 2:52 pm
Could be a bug... can you post an
MCVE that I can try?
Re: Dynamic Listviews
Posted: Sun Apr 25, 2021 5:47 pm
by airsoftsoftwair
The way you use
Group.InitChange and
Group.ExitChange looks unnecessarily complex albeit not wrong. Can you try if it works when using this code instead:
Code: Select all
moai.DoMethod("mylistview", "initchange")
moai.DoMethod("mylistview", "remove", "listview1")
moai.CreateObject(listviewXml$, "mylistview")
moai.DoMethod("mylistview", "append", "listview1")
moai.DoMethod("mylistview", "exitchange", False)
This will remove and replace the listview in one init-exit-change cycle.
Re: Dynamic Listviews
Posted: Sun Apr 25, 2021 6:43 pm
by davec
I had to keep the FreeObject() call, but no, still doesn't dynamically update in Android.
airsoftsoftwair wrote: ↑Sun Apr 25, 2021 5:47 pm
The way you use
Group.InitChange and
Group.ExitChange looks unnecessarily complex albeit not wrong. Can you try if it works when using this code instead:
Code: Select all
moai.DoMethod("mylistview", "initchange")
moai.DoMethod("mylistview", "remove", "listview1")
moai.CreateObject(listviewXml$, "mylistview")
moai.DoMethod("mylistview", "append", "listview1")
moai.DoMethod("mylistview", "exitchange", False)
This will remove and replace the listview in one init-exit-change cycle.
Re: Dynamic Listviews
Posted: Sun May 02, 2021 7:25 pm
by airsoftsoftwair
Ok, this was a bug in RapaGUI on Android. It's fixed now!
Re: Dynamic Listviews
Posted: Mon May 03, 2021 5:55 am
by davec
So would this require a new version of the Android compiler?
Thanks,
Dave
airsoftsoftwair wrote: ↑Sun May 02, 2021 7:25 pm
Ok, this was a bug in RapaGUI on Android. It's fixed now!
Re: Dynamic Listviews
Posted: Mon May 03, 2021 9:02 pm
by airsoftsoftwair
Yes. An update will be released once RapaGUI 2.0 is out.