Dynamic Listviews

Discuss GUI programming with the RapaGUI plugin here
Post Reply
davec
Posts: 21
Joined: Thu Sep 03, 2020 10:39 pm

Dynamic Listviews

Post 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)
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Dynamic Listviews

Post by airsoftsoftwair »

Could be a bug... can you post an MCVE that I can try?
davec
Posts: 21
Joined: Thu Sep 03, 2020 10:39 pm

Re: Dynamic Listviews

Post 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?
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Dynamic Listviews

Post 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.
davec
Posts: 21
Joined: Thu Sep 03, 2020 10:39 pm

Re: Dynamic Listviews

Post 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.
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Dynamic Listviews

Post by airsoftsoftwair »

Ok, this was a bug in RapaGUI on Android. It's fixed now!
davec
Posts: 21
Joined: Thu Sep 03, 2020 10:39 pm

Re: Dynamic Listviews

Post 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!
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Dynamic Listviews

Post by airsoftsoftwair »

Yes. An update will be released once RapaGUI 2.0 is out.
Post Reply