Android Question [SOLVED] B4XTable - "Custom layouts" of headers

LucaMs

Expert
Licensed User
Longtime User
I've been literally fighting 🤬 with the column headers of a B4XTable for many hours (not consecutively, "fortunately").

Only now did I see this thread:

https://www.b4x.com/android/forum/threads/b4x-b4xtable-with-custom-cells-layout.102352/

but for the moment I still don't know if it will help me, mainly because I ADD views, to the headers and by loading a layout.

What I do is load into the header cell a layout containing a basic panel that has some Views (one of this is a B4XImageView, for this reason I don't create the layout by code, unlike the example in that thread). I assign a tag to the panel, let's say "Goofy".

Subsequently I want to be able to remove the panel, so I search and find the panel with the "Goofy" tag, I empty it with RemoveAllViews and finally I remove the panel itself, with RemoveViewFromParent.

Once this is done, however, the header no longer seems to have a "layout", the text remains but not the initial colored and "bordered" rectangle. The worst thing is that when you click on it, the project crashes, because Row in this line (B4XTable source code) do not contains a number:
B4X:
Private Sub CellClicked (pnl As B4XView, LongClicked As Boolean)
    If DateTime.Now < LastCellClickEvent + 20 Then Return
    LastCellClickEvent = DateTime.Now
    Dim column As B4XTableColumn = pnl.Parent.Tag
    Dim Row As Int = pnl.Tag - 1 ' <----
as if I had changed that pnl.Parent.Tag or had created that pnl again.


I know this is hard to understand.
I hope for Erel's great intelligence (I'm very envious😄 [really, I'm not kidding]) and tomorrow or maybe sooner I'll attach an example.


[Too bad today is Friday (I don't specify the reason for this)]


[BTW] To test, I loaded the B4XTable source and all its dependencies, including the layout file. Strangely, the cells remain empty. I saw that the problem depends on AddNonQueryToBatch, but I didn't investigate further.
 

MicroDrie

Well-Known Member
Licensed User
I can understand removing a view, but I don't understand throwing away the panel. Why can't you add an empty view to that panel after removing the view(s) to prevent you from referencing anything? Or better, what exactly do you want to achieve?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I can understand removing a view, but I don't understand throwing away the panel.
It is a panel I add (layout file), so I have to remove it, to "restore" the initial-default state-look-layout.

Or better, what exactly do you want to achieve?
1 - create the columns
2 - fill the B4XTable with data

When the user wishes, he can change the layout of the headings. I'm writing a "wrapper class" to allow this. I load a layout file in the header cells and then the user shoud be able to return to the initial state, remove all the views added to the header cell, i.e. a basic panel containing N views.
This works, as I remove that added panel, including its views, but the initial look changes and, worse, its "parent" tag seems to "disappear".

It's complicated, I'll post an example.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
What about to remove the views and the panel and then add the tag to the header to point to panel less header?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
tomorrow or maybe sooner I'll attach an example.
B4J example attached.

Click on the CheckBox, the custom layout will be loaded in the header cell; click again and the basic custom layout panel will be removed, along with its views. At this point the cell will no longer have its original "look" and, worse still, clicking on it to sort the column values will cause the project to crash, because...

(from the first post)
1703221555853.png


P.S. I updated the attached project, one little thing was missing.
 

Attachments

  • ChangeHeadersRuntime.zip
    13.1 KB · Views: 29
Last edited:
Upvote 0
Top