J JackSparrow Member Nov 16, 2022 #1 Hi all, I have 2 CustomListViews with panels which are almost duplicates in the fact that they use the same controls and labels. Everything seems to be working ok except that i am having problems identifying from which panel a button is being pressed. The code for the button press is simple B4X: Copy Dim button As B4XView = Sender Try Dim index As Int = clv1.GetItemFromView(Sender) Dim Pnl As B4XView = clv1.GetPanel(index) Catch Log(LastException) Dim index As Int = clv2.GetItemFromView(Sender) Dim Pnl As B4XView = clv2.GetPanel(index) End Try Dim lbl As B4XView = dd.GetViewByName(Pnl, "Total") I can press either panel's button multiple times with no problem, then go to the next panel and press that but and all ok but if I then go to the first panel again I get a crash 1st line of error is this ' java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.View After searching the forum I have come to the conclusion that it's because of multiple error catching at the catch try block, however I am unsure as to how I can identify the correct customListView (clv1 or clv2) Other relevant code is as follows B4X: Copy Private clv1 As CustomListView Private clv2 As CustomListView ... clv1.AsView.Tag = clv1 clv2.AsView.Tag = clv2 Does anyone have any idea how I might be able to identify from which panel the button is pressed so that I can access the correct customlistview Many Thanks
Hi all, I have 2 CustomListViews with panels which are almost duplicates in the fact that they use the same controls and labels. Everything seems to be working ok except that i am having problems identifying from which panel a button is being pressed. The code for the button press is simple B4X: Copy Dim button As B4XView = Sender Try Dim index As Int = clv1.GetItemFromView(Sender) Dim Pnl As B4XView = clv1.GetPanel(index) Catch Log(LastException) Dim index As Int = clv2.GetItemFromView(Sender) Dim Pnl As B4XView = clv2.GetPanel(index) End Try Dim lbl As B4XView = dd.GetViewByName(Pnl, "Total") I can press either panel's button multiple times with no problem, then go to the next panel and press that but and all ok but if I then go to the first panel again I get a crash 1st line of error is this ' java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.View After searching the forum I have come to the conclusion that it's because of multiple error catching at the catch try block, however I am unsure as to how I can identify the correct customListView (clv1 or clv2) Other relevant code is as follows B4X: Copy Private clv1 As CustomListView Private clv2 As CustomListView ... clv1.AsView.Tag = clv1 clv2.AsView.Tag = clv2 Does anyone have any idea how I might be able to identify from which panel the button is pressed so that I can access the correct customlistview Many Thanks
Solution Erel Nov 16, 2022 Why not assign the CLV to the button's tag property: Code: Copy pnl.LoadLayout("ItemLayout") dd.GetViewByName(Pnl, "Button1").Tag = CorrectCLV This will allow you to easily find the correct one later.
Why not assign the CLV to the button's tag property: Code: Copy pnl.LoadLayout("ItemLayout") dd.GetViewByName(Pnl, "Button1").Tag = CorrectCLV This will allow you to easily find the correct one later.
Erel B4X founder Staff member Licensed User Longtime User Nov 16, 2022 #2 Why not assign the CLV to the button's tag property: Code: Copy pnl.LoadLayout("ItemLayout") dd.GetViewByName(Pnl, "Button1").Tag = CorrectCLV This will allow you to easily find the correct one later. Upvote 0 Solution
Why not assign the CLV to the button's tag property: Code: Copy pnl.LoadLayout("ItemLayout") dd.GetViewByName(Pnl, "Button1").Tag = CorrectCLV This will allow you to easily find the correct one later.
J JackSparrow Member Nov 16, 2022 #3 Erel said: Why not assign the CLV to the button's tag property: Code: Copy pnl.LoadLayout("ItemLayout") dd.GetViewByName(Pnl, "Button1").Tag = CorrectCLV This will allow you to easily find the correct one later. Click to expand... Thank you Erel, I played around with the tag property for ages and last night I eventually came up with something similar that works. I was going to post the solution and saw yours B4X: Copy clv2.Add(CreateListItem("Test", clv2.AsView.Width, 50%y,2), "") Sub CreateListItem(Text As String, Width As Int, Height As Int,Tag As Int) As B4XView . . . dd.GetViewByName(p,"button1").Tag=Tag Not as elegant as your code but it works Upvote 0
Erel said: Why not assign the CLV to the button's tag property: Code: Copy pnl.LoadLayout("ItemLayout") dd.GetViewByName(Pnl, "Button1").Tag = CorrectCLV This will allow you to easily find the correct one later. Click to expand... Thank you Erel, I played around with the tag property for ages and last night I eventually came up with something similar that works. I was going to post the solution and saw yours B4X: Copy clv2.Add(CreateListItem("Test", clv2.AsView.Width, 50%y,2), "") Sub CreateListItem(Text As String, Width As Int, Height As Int,Tag As Int) As B4XView . . . dd.GetViewByName(p,"button1").Tag=Tag Not as elegant as your code but it works