Hi,
How to change the background colour of an individual item before .AddTextItem ?
Paul
'Adds a text item. The item height will be adjusted based on the text.
Public Sub AddTextItem(Text As String, Value As Object, BackgroundColor As Int)
InsertAtTextItem(items.Size, Text, Value, BackgroundColor)
End Sub
'Inserts a text item at the specified index.
Public Sub InsertAtTextItem(Index As Int, Text As String, Value As Object, BackgroundColor As Int)
Dim pnl As Panel
pnl.Initialize("")
Dim lbl As Label
lbl.Initialize("")
lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
pnl.AddView(lbl, 5dip, 2dip, sv.Width - 5dip, 20dip)
lbl.Text = Text
lbl.TextSize = DefaultTextSize
lbl.TextColor = DefaultTextColor
' If DefaultTextBackground <> Null Then
'pnl.Background = DefaultTextBackground
'Else
pnl.Color = BackgroundColor
'End If
Dim minHeight As Int
minHeight = su.MeasureMultilineTextHeight(lbl, Text)
lbl.Height = Max(50dip, minHeight)
InsertAt(Index, pnl, lbl.Height + 2dip, Value)
End Sub
For i = 1 To 10
If i = 10 Then
clv2.AddTextItem("Text"&i,"",Colors.Blue)
Else
clv2.AddTextItem("Text"&i,"",Colors.Red)
End If
Next
You can change the backcolor just after adding the new item:How to change the background colour of an individual item before .AddTextItem ?
clv1.GetPanel(clv1.GetSize -1).Color = Colors.Blue
'Adds a text item. The item height will be adjusted based on the text.
' Pass BackgroundColor = -1 to use default background.
Public Sub AddTextItem(Text As String, BackgroundColor As Int, Value As Object)
InsertAtTextItem(items.Size, Text, BackgroundColor, Value)
End Sub
'Inserts a text item at the specified index.
' Pass BackgroundColor = -1 to use default background.
Public Sub InsertAtTextItem(Index As Int, Text As String, BackgroundColor As Int, Value As Object)
Dim pnl As Panel
pnl.Initialize("")
Dim lbl As Label
lbl.Initialize("")
lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
pnl.AddView(lbl, 5dip, 2dip, sv.Width - 5dip, 20dip)
lbl.Text = Text
lbl.TextSize = DefaultTextSize
lbl.TextColor = DefaultTextColor
If BackgroundColor <> - 1 Then
pnl.Color = BackgroundColor
Else
If DefaultTextBackground <> Null Then
pnl.Background = DefaultTextBackground
Else
pnl.Color = DefaultTextBackgroundColor
End If
End If
Dim minHeight As Int
minHeight = su.MeasureMultilineTextHeight(lbl, Text)
lbl.Height = Max(50dip, minHeight)
InsertAt(Index, pnl, lbl.Height + 2dip, Value)
End Sub
Of course, just use a bitmap with 3 dots and show a panel (menu) on click.
Something like this (attached); it is ugly, I knowOf course, just use a bitmap with 3 dots and show a panel (menu) on click.
Something like this (attached); it is ugly, I know, but with few changes...!
Please start a new thread for this question in the questions forum. Also describe how you are filling the list and how long does it take.
Sub OnOff_CheckedChange(Checked As Boolean)
Msgbox("Cambio de Status","Cambio")
End Sub
Look at Erel's example on Post 1; it shows how to get the view from the each CLV base panel
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:com.alarma.clock
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (alarma) Create **
Error occurred on line: 216 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
at com.alarma.clock.customlistview._getitemfromview(customlistview.java:84)
at com.alarma.clock.main._onoff_checkedchange(main.java:827)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.objects.CompoundButtonWrapper$1.onCheckedChanged(CompoundButtonWrapper.java:44)
at android.widget.CompoundButton.setChecked(CompoundButton.java:154)
at android.support.v7.widget.SwitchCompat.setChecked(SwitchCompat.java:1066)
at de.amberhome.objects.appcompat.ACSwitchCompatWrapper.DesignerCreateView(ACSwitchCompatWrapper.java:63)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:70)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:831)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at com.alarma.clock.alarma.onCreate(alarma.java:54)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2907)
at android.app.ActivityThread.access$2200(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
'Returns the index of the item that holds the given view.
Public Sub GetItemFromView(v As View) As Int
Dim parent = v, current As Object
Do While (parent Is Panel) = False Or sv.Panel <> parent
current = parent
Dim jo As JavaObject = current
parent = jo.RunMethod("getParent", Null)
Loop
v = current
Return v.Tag
End Sub
Sub OnOff_CheckedChange(Checked As Boolean)
'If CargaInicial Then Return
Dim index As Int= ClvAlarmas.GetItemFromView(Sender)
Dim pnl As Panel = ClvAlarmas.GetPanel(index)
Dim chk As ACSwitch = pnl.GetView(3)
Msgbox($"Item value: ${ClvAlarmas.GetValue(index)}
Check value: ${chk.Checked}"$, "")
End Sub
Did you manage to make a Drag&Drop between Customlistviews possible?What is the best way do a drag - drop between 2 CustomListViews?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?