I have a Problem, i have 4 Color, and 1 Panel.
I add the Panel in my ListView and by adding the next panel into the ListView i will a new Color for my Panel.
I need a Loop, after the 4. Color return to the first color.
I have no Idia how to programm it :/
My Code:
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
Activity.AddView(p, 0, 0, Width, Height)
p.LoadLayout("frm_content")
p.RemoveView
'label1 and button1 will point to the last added views.
Return p
End Sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("frm_main")
For i = 1 To 10
clv1.Add(CreateListItem($"Item #${i}"$, clv1.AsView.Width, 150dip), 150dip, $"Item #${i}"$)
Next
End Sub
B4X:
Sub Globals
Private pnl_content001 As Panel
End Sub
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private data As List
End Sub
Public Sub Initialize
data.Initialize
End Sub
Public Sub nextitem As Object
Dim o As Object = data.Get(0)
data.RemoveAt(0)
data.Add(o)
Return o
End Sub
Public Sub Push(o As Object)
data.Add(o)
End Sub
Public Sub Pop As Object
Dim o As Object = data.Get(data.Size - 1)
data.RemoveAt(data.Size - 1)
Return o
End Sub
Public Sub Peak As Object
Return data.Get(data.Size - 1)
End Sub
Public Sub getSize As Int
Return data.Size
End Sub
Example use:
B4X:
tools.Initialize
tools.Push(Colors.Black)
tools.Push(Colors.Red)
tools.Push(Colors.Yellow)
tools.Push(Colors.Transparent)
For i = 0 To 99
Log(tools.nextitem)
Next
So, basically in your Create item method you do a
B4X:
dim color as int = tools.nextitem
' Use this color to set it to the active panel
You must be more accurate. CustomListView and ListView are two different things.
B4X:
Sub Process_Globals
Private MyColors() As Int = Array As Int(Colors.Red, Colors.Green, Colors.Blue, Colors.Black)
Private ColorIndex As Int
End Sub
Sub CreateListItem
...
p.Color = MyColors(ColorIndex)
ColorIndex = (ColorIndex + 1) Mod MyColors.Length
Return p
End Sub
Incrementing a pointer to get the colour from an array is how I would have approached the problem. But I would have used an If statement to determine when the array length was exceeded and thus reset the pointer back to zero.
B4X:
ColorIndex = (ColorIndex + 1) Mod MyColors.Length
@Erel very nice code, I'll have to try and remember to use the Mod function in the future! Very neat!!
Private MyColors() As Int = Array As Int(Colors.RGB(74,74,82), Colors.RGB(132,121,121), Colors.RGB(152,99,122), Colors.RGB(162,116,92))
Private ColorIndex As Int
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
Activity.AddView(p, 0, 0, Width, Height)
p.LoadLayout("frm_content")
p.RemoveView
'label1 and button1 will point to the last added views.
p.Color = MyColors(ColorIndex)
ColorIndex = (ColorIndex + 1) Mod MyColors.Length
Return p
End Sub
I´m VisualBasic Developer, this language ist new for me
You load a layout file to the panel (p) "frm_content". Make sure the layout has a transparent backround.
EDIT: does your layout contains a panel? do you want to change that panel color? the code you posted above will change the CLV item background color.
each item in a CLV is basically a panel and you change the color of it but if you load a layout that contains another view then you need to change the color of that view.
sure you want to use a PRIVATE variable? If the variable is declared outside of our sub then your sub does not have access to the right variable.
I suggest to use a Global PUBLIC valiable for the list and the indexvariable.
Dim pnl_content As Panel
ppnl_content.Color = MyColors(ColorIndex)
So now i have a Problem, i will on the ground a imageview like the Picture, but the Problem is, the CustomListView is on Top and my ImageView in the background.
How can i fix it?
Dim pnl_content As Panel
ppnl_content.Color = MyColors(ColorIndex)
So now i have a Problem, i will on the ground a imageview like the Picture, but the Problem is, the CustomListView is on Top and my ImageView in the background.
How can i fix it?
you can add an imageview to the activity via designer or via code and then call
imageview.BringtoFront and it will be in z order on the top place.
btw, "will" in english means something different then in german. will in english means "werde..." like "ich werde morgen..." i will tomorrow...
the right word is "want", "i want..." (ich will...)