Android Question ColorsList class - strange effect

Phayao

Active Member
Licensed User
Longtime User
Hello,

I was about to implement the colorslist example in my application.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim xui As XUI
    Private pnlCols As Panel

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")    <==== includes ColorsList1 customview inside panel pnlCols
    pnlCols.Visible = False
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub lblCol_click    ' show colorpanel as panel
    Dim lbl As Label = Sender
    pnlCols.Visible = True
End Sub

Sub ColorsList1_ItemClick (cname As String, Clr As Int)
    Log("received name = "& cname)
    Activity.Color = Clr
    pnlCols.Visible = False
End Sub

ColorsList class:
B4X:
#Event: ItemClick (Clr As Int)
Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As B4XView 'ignore
    Private xui As XUI 'ignore
    
    Private colorslv As CustomListView   <==== error:  is not initialized !!
    Private ColorLabel As B4XView
    Private ColorPanel As B4XView
    
    Private editsearchCol As EditText
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
    Log(EventName)
End Sub

Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
    Sleep(0) 'cannot load layouts in DesignerCreateView without calling Sleep before
    mBase.LoadLayout("listtemplate")
    colorslv.sv.SetColorAndBorder(xui.Color_Transparent, 0, 0, 0)    <==== error in runtime: null object reference !!

So even the layout "main" contains ColorsList1 as customview, the class doesn't recognize colorslv as already initialized ...

If anybody has an idea, i really appreciated - after days of experimentation I cannot explain the behaviour,

Thanks, Chris
 

Attachments

  • designer.png
    designer.png
    94.3 KB · Views: 171

PaulMeuris

Well-Known Member
Licensed User
In the tutorial you mention the author (Erel) suggest:
- A more powerful color picker implemented as a dialog is included in XUI Views.
Here's an example using the B4XColorTemplate:

Using B4XColorTemplate:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private colordialog As B4XDialog    'XUI views library
    Private Button1 As Button
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    colordialog.Initialize(Root)
End Sub
Private Sub Button1_Click
    Dim input As B4XColorTemplate
    input.Initialize
    Wait For (colordialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Resultdate As Int)
    If Resultdate = xui.DialogResponse_Positive Then
        MsgboxAsync(input.SelectedColor,"Selected color")
        Button1.Color = input.SelectedColor
    End If
End Sub
Check out the images attached.
If you need the color names then you can use the colors list or you can find a list of web colors with names on the internet.
Example: Color list
I haven't tested the colors list yet.
Greetings from Pattaya,
Paul
 

Attachments

  • colorpicker_1.PNG
    colorpicker_1.PNG
    1.4 KB · Views: 166
  • colorpicker_2.PNG
    colorpicker_2.PNG
    65 KB · Views: 174
  • colorpicker_3.PNG
    colorpicker_3.PNG
    7.8 KB · Views: 175
  • colorpicker_4.PNG
    colorpicker_4.PNG
    1.7 KB · Views: 158
Upvote 0
Top