This is an interface library to help with managing CellFactories for ListView and TableViews.
The principle job of a cell factory is to display data into a cell. The standard ListView and TableViews use a default CellFactory. With this interface, you can create a custom cellfactory and change the appearance of the cells within a ListView and columns within a TableView.
The Library is in two parts, a Java Library that manages the callback required for the ListView to display the data as configured by the cell factory. And a B4j class that allows manipulation of the cell factory.
Usage :
To set up a cell factory, you first need to create an instance of the LVCellFactoryHelper (or TVCellFactoryHelper):
It's parameters are a Type, either Text or Graphic(which is a bit of a misnomer as it is actually a Node that can hold other objects), an ID for use within the CellObject Class and the ListView or TableView Column that will hold the CellFactoryObjects.
Then, rather than adding our data directly into a List or Column, we need to create a CellObject for all of the items in a list or column that we want to manage. The CellObject will create and initialize a CellFactoryObject which is the object that needs to be added to the ListView or Column and can be obtained by calling the CellFactoryObject method of the CellObject:
Then we can write the code within the CellObject class that will determine how the data is displayed.
Examples :
There are currently 4 examples attached to this post, I plan at least one more on utilizing Drag and Drop.
The Simple Text example allows a firstname and lastname field to be reversed, and contains a numeric score which triggers a Style to color the cell if the score is >= 90.
The Simple Graphic example does the same, but the Score is in a separate label and so appears aligned.
The Graphic Object Example manages two lists with one CellObject (I could have written two separate classes) And shows or hides a button on each of the lists.
The TableView Editable Example uses an editable TextField and a hideable button in one column.
Download and unzip the Library Jar and Xml files in jCellFactoryHelper.zip to your Addl Libs directory.
I hope it all makes sense. By its nature, it is not particularly simple but I hope you can make use of it.
The principle job of a cell factory is to display data into a cell. The standard ListView and TableViews use a default CellFactory. With this interface, you can create a custom cellfactory and change the appearance of the cells within a ListView and columns within a TableView.
The Library is in two parts, a Java Library that manages the callback required for the ListView to display the data as configured by the cell factory. And a B4j class that allows manipulation of the cell factory.
Usage :
To set up a cell factory, you first need to create an instance of the LVCellFactoryHelper (or TVCellFactoryHelper):
B4X:
Dim CFH As LVCellFactoryHelper
CFH.Initialize(CFH.TYPETEXT,"Id",lvName)
It's parameters are a Type, either Text or Graphic(which is a bit of a misnomer as it is actually a Node that can hold other objects), an ID for use within the CellObject Class and the ListView or TableView Column that will hold the CellFactoryObjects.
Then, rather than adding our data directly into a List or Column, we need to create a CellObject for all of the items in a list or column that we want to manage. The CellObject will create and initialize a CellFactoryObject which is the object that needs to be added to the ListView or Column and can be obtained by calling the CellFactoryObject method of the CellObject:
B4X:
Dim CO As CellObject
CO.Initialize("Text","Btn" )
Row(0) = CO.CellFactoryObject
Then we can write the code within the CellObject class that will determine how the data is displayed.
Examples :
There are currently 4 examples attached to this post, I plan at least one more on utilizing Drag and Drop.
The Simple Text example allows a firstname and lastname field to be reversed, and contains a numeric score which triggers a Style to color the cell if the score is >= 90.
The Simple Graphic example does the same, but the Score is in a separate label and so appears aligned.
The Graphic Object Example manages two lists with one CellObject (I could have written two separate classes) And shows or hides a button on each of the lists.
The TableView Editable Example uses an editable TextField and a hideable button in one column.
Download and unzip the Library Jar and Xml files in jCellFactoryHelper.zip to your Addl Libs directory.
I hope it all makes sense. By its nature, it is not particularly simple but I hope you can make use of it.
Attachments
Last edited: