Android Question Designer

Guenter Becker

Active Member
Licensed User
Longtime User
I have customview class XY
In the class a scrollview is declared and I added labels as childviews to the scrollview by code.
In the initialize sub of the class I initialized the labels like abc.initialize("abc").
To capture label clicks I have the sub abc_click in the class.
In the customview class #EVENT: Click is the 1st line to have a click event for my custom view in the activity.
In the activity I have a sub XY1_click.

If I run the app
- the layout is loaded and shown well
- if I click on a label the jump to the class sub abc_click is done well.
- the click Event of the designer to got to XY1_click is not fired? Why?
- I tried to have a sleep(0) in the abc_click sub but this does not help.

Whats going wrong?
Stay well and best regards
Guenter
 
Ok understood. Thank you.
 
Upvote 0
You need to implement the label click events inside the class. You can then raise your own events with CallSub.

Hello again,
This is targeting the same Probleme in Addition to the views in my customview implemented a customlistview by code Sub Globals: Private clv as customlistview.
I used the Initialize Sub of the class and tried clv.Intitialize(clv,"clv") and clv.Initialize("mcallback,"clv"). In the class I added a Sub clv_ItemClick(Index as int, Value as Object).
If I run the code I can see that an listviewitem is clicked (flashes) but there is no jump to the event sub. Any Idea whats wrong?
Than you in advance
cheers Guenter
 
Upvote 0
If I run the code I can see that an listviewitem is clicked (flashes) but there is no jump to the event sub. Any Idea whats wrong?
Possibly upload a bare / basic example project . (just load some dummy text to the clv)
 
Upvote 0
Hi Friend you are welcome,

find next the code for the customview class :
[CODE lang="b4x" title="Example class" highlight="36,46,61,153"]'#Event: ItemClicked(Index As Int, Value As Object)

#DesignerProperty: Key: OpenId, DisplayName: ID to show, FieldType: Int, DefaultValue: 0, Description: ID of Parent and Child ID to be shown.
#DesignerProperty: Key: TitleHeight, DisplayName: Title Text Height, FieldType: Int, DefaultValue: 20, Description: Textheight of the Title.
#DesignerProperty: Key: IntendWidth, DisplayName: Intend Width, FieldType: Int, DefaultValue: 50, Description: Width of the Child intend form the left.
#DesignerProperty: Key: ParentTextSize, DisplayName: Parent Text Height, FieldType: Int, DefaultValue: 18, Description: Textheight of the Menuparent (Branch).
#DesignerProperty: Key: ChildTextSize, DisplayName: Child Text Height, FieldType: Int, DefaultValue: 14, Description: Textheight of the Child (Leaf).


#DesignerProperty: Key: BackgroundColor, DisplayName: Background color, FieldType: color, DefaultValue:0xFFFFFFFF, Description: Controls Background color.
#DesignerProperty: Key: TitelBackgroundColor, DisplayName: Titel Background color, FieldType: color, DefaultValue:0xFFFFFFFF, Description: Title Background color.
#DesignerProperty: Key: TitelTextColor, DisplayName: Titel Text color, FieldType: color, DefaultValue:0xFF000000, Description: Title Text color.
#DesignerProperty: Key: ParentTextColor, DisplayName: Parent Text Color, FieldType: color, DefaultValue: 0xFF000000, Description: Textcolor of the Parent.
#DesignerProperty: Key: ChildTextColor, DisplayName: Child Text Color, FieldType: color, DefaultValue: 0xFF000000, Description: Textcolor of the Parent.
#DesignerProperty: Key: ParentColor, DisplayName: Parent Background Color, FieldType: color, DefaultValue: 0xFFFFFFFF, Description: Backgroundcolor of the Parent Panel.

#DesignerProperty: Key: ChildColor, DisplayName: Child Background Color, FieldType: color, DefaultValue: 0xFFFFFFFF, Description: Backgroundcolor of the Child Panel.



Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Private xui As XUI 'ignore
Public Tag As Object

'Public Scv As ScrollView
Type TMI ( _
ID As Int, _
ParentID As Int, _
BM As Bitmap, _
Txt As String, _
Show As Boolean, _
HasChildren As Boolean)
Private clv As CustomListView
Public ItemList As List
Private props1 As Map
End Sub

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

'Scv.Initialize(100dip)
clv.Initialize(mCallBack,"clv")
ItemList.Initialize
props1.Initialize
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, props As Map)
mBase = Base
Tag = mBase.Tag
mBase.Tag = Me

props1 = props
' set parameters
'clv.Width=mBase.Width
'clv.height= mBase.height
mBase.AddView(clv.AsView,0,0,mBase.Width,mBase.Height)

End Sub

Private Sub Base_Resize (Width As Double, Height As Double)

End Sub

' # build the panel for one item
Sub buildItem(item As TMI) As Panel
Try
Dim t As Label ' Branch label
t.Initialize("MenuItemClicked")
t.Text = item.txt
If item.ParentID = 0 Then
t.Textcolor = props1.Get("ParentTextColor")
t.TextSize = props1.Get("ParentTextSize")
t.Typeface = Typeface.DEFAULT_BOLD
Else
t.Textcolor = props1.Get("ChildTextColor")
t.TextSize = props1.Get("ChildTextSize")
End If
t.Height = t.TextSize + 10
If item.ParentID <> 0 Then t.Tag = item.parentid

Dim ind As Label ' Intend
ind.Initialize("MenuItemClicked")
ind.Width = props1.Get("IntendWidth")
ind.Height = t.height
If item.ParentID <> 0 Then ind.tag = item.parentid

Dim i As ImageView ' Branch Image
i.Initialize("MenuItemClicked")
i.Height = t.Height
i.Width = i.Height
If item.ParentID <> 0 Then i.Tag=item.parentid
If item.bm.isinitialized Then i.Bitmap=item.bm

' stretch label to full width
t.Width =clv.asview.Width -10 - i.Width -10 -10

Dim p As Panel ' Main Branchpanel
p.Initialize("p")
p.RemoveAllViews
p.Height = t.height
If item.ParentID <> 0 Then p.Tag = item.parentid
If p.Height < i.Height Then p.Height=i.height
If p.Height < t.Height Then p.Height=t.height
If item.ParentID=0 Then
p.Color = props1.Get("ParentColor")
Else
p.Color = props1.Get("ChildColor")
End If
' add views to the panel
If item.ParentID = 0 Then
p.addview(i,10,0,i.Width,i.Height)
p.AddView(t,10 + i.Width + 10,0,t.Width,t.height)
p.Width = 10 + i.Width + 10 + t.width
Else
p.addview(ind,10,0,ind.width,ind.height)
p.addview(i,10 + ind.Width +10,0,i.Width,i.Height)
p.AddView(t,10 + ind.width + 10 + i.Width +10,0,t.Width,t.height)
p.Width = 10 + ind.Width + 10 + i.Width+10+t.width
End If
' return panel as tree row
Return p
Catch
xui.Msgbox2Async(LastException,"Error FTM1","OK","","",Null)
Return Null
End Try
End Sub

' # add the items to the customlistview
public Sub buildTree
Try
Dim item As TMI
Dim p As Panel
p.Initialize("p")
clv.clear
For x = 0 To ItemList.Size-1
item = ItemList.Get(x)
'Log("V" & r & " " & item.Txt & " " & Scv.height)
p = buildItem(item)
'Scv.Panel.AddView(p,0,r,p.Width,p.Height)
If item.Show = True Then clv.Add(p,p.Height,item.id)
Next
Catch
xui.Msgbox2Async(LastException,"Error FTM2","OK","","",Null)
End Try
End Sub

' # listview item click event
Sub clv_ItemClick (Index As Int, Value As Object)
Try
Log(Sender)
' Get the menu item via ID = Value
Dim p As Panel = clv.GetPanel(Index).GetView(0)
Dim item As TMI
item = ItemList.Get(Value)

If item.HasChildren = False Then ' single Branch or child
Select Case Value
Case 1
' action
End Select
Else
' Toggle show/hide
For x = 0 To ItemList.Size-1
item = ItemList.Get(x)
If item.ID = Value Or item.ParentID = Value Then
item.Show = Not(item.show) ' switch
ItemList.Set(x,item) ' change the value
End If
Next
' rebuild the tree
buildTree
End If
Catch
xui.Msgbox2Async(LastException,"Error FTM3","OK","","",Null)
End Try
End Sub

'Private Sub Xclv_ItemClick(Index As Int, Value As Object)
' If SubExists(mCallBack, mEventName & "_ItemClick") Then
' 'raise the Click event , passing selected parameters
' CallSub3(mCallBack, mEventName & "_ItemClick", Index, Value)
' End If
'End Sub[/CODE]

I marked the lines where I assume a failure. All this code is working fine except itemclick event is does not reach sub in line 153.

cheers Guenter
 
Upvote 0
From what I am Reading (in 2 threads regarding this issue) it is the Click_Event in your Main Activity that is not firing.
Posting code for your Custom class will not help (It looks OK)

Again ... Please upload your project or a basic sample project that demonstrates the issue.
File > Export as Zip.
 
Upvote 0
The outcommenting is only to solve the problems step by step. At this time I have tried several solutions but I am always running in a circle not getting the event problems solved.

The clv event in the custom class is not jumping to the event sub and the event in the first line is not working as well. The possibility to call the sub as action inside the custom class event sub will only help if this sub is adressed by the item click event of the clv view.

My target is to publish this custom view to the forum. I know that there are other solutions. I tested them but they have all not the ability to predefine menu parameters I and others need by designer props. The closes one fit the needs is the customview 'SD_Tree' but this one has a fixed height of 40 dpi per treerow and if you are using a textsize of the row element greater then 14 dpi the lower part of the letter (for example 'g') is truncated. At the end I made the decision to develop a Treemenu by my own that has all the possibilities several forum members are looking for. As I pointed out before the main part of the code is working only the problems of the not working events ar e remaining.

cheers Guenters
 

Attachments

Upvote 0
Whilst I could not get your project to run (error regarding clv .. Are you using the latest xCustomListView Internal lib ?) ...

I could not help notice,

FoldableMenuTree class ... _ItemClick !
Code:
Sub clv_ItemClick (Index As Int, Value As Object)
'--------------------
If SubExists(mCallBack,mEventName & "_ItemClick") Then
' call sub in activizy/page parent of FoldableListview
' Sub name will be FoldableTreeMenue1:ItemClick(Index As Int, Value As Object)
CallSub3(mCallBack, mEventName & "_ItemClick", Index, Value)
'--------------------


In you Main Activity ... _ItemClicked !
Code:
Sub FoldableTreeMenu1_ItemClicked(Index As Int, Value As Object)
    Log("X")
End Sub
 
Upvote 0
Back
Top