Android Question [Solved] [B4XTable] Restore a cell's background color after SingleClick event

GabrielM

Member
Licensed User
Longtime User
In a B4A application, in a B4XTable, I need to have a cell background color changed to Red color (for example).
This cell is supposed to maintain its background color till a decision to change it.

The issue I need to address is that :
- after the respective cell's background was changed to a needed color, if I click on that cell, triggering the SingleClick event, its background will be restored to default (white color).

Is there any specific action to restore the cell's background color to whatever it was before the SingleClick ?

I have attached the B4A code ( actually a modified example from this forum, where I have modified the "Next" Button action to mark a cell background colour to Red (Column "Name", Row: 1).
 

Attachments

  • B4XTable Cell Background Color.zip
    60.9 KB · Views: 297

Mahares

Expert
Licensed User
Longtime User
The issue I need to address is that :
- after the respective cell's background was changed to a needed color, if I click on that cell, triggering the SingleClick event, its background will be restored to default (white color).
The first thing that comes to mind is to use: B4XTableSelections class which is an extension to B4XTable. Here is the link with an example. After you add the class module, you must also select B4XCollections library. You may want to practice with the example in that class.
The mode you select will be: XSelections.Mode = XSelections.MODE_SINGLE_CELL_PERMANENT. You can change the cell clicked color when clicked to any color you choose in the B4XTable designer section.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Thanks Mahares,
Was trying that as well, previously.

The cell clicked will loose its previously custom background color if you do a SingleClick on it, unfortunately.

Probably, I will need to redo the background color, add some flags etc.
Hope it was an easier way.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The cell clicked will loose its previously custom background color if you do a SingleClick on it, unfortunately.
Here is your project with my changes by adding the B4XTable extension. If you click on a cell its background color changes to the pressed color. you choose in the designer. If you click on it again, it reverts back to the original look. If this is not satisfactory, please explain with an example exactly what you mean.
 

Attachments

  • B4XTableGabriel102420.zip
    62.4 KB · Views: 291
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Ok, so lets say we start with the cell color being say "white" in the designer.
>Then, in the program, at some point, make it "red" and try to keep it "red", after you SingleClick it.
Does is still keep the "red" background ?
Example is attached to initial post.
Thanks.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Thank you very much Mahares, really appreciating your time for helping me.
Have tried it and it does not restore the background red color of the cell in column "Name" row 1 after you single click it.

Try this:
- start app
- click the left bottom side "next" blue button. the cell background in column "Name" row 1 will be marked red.
- now, if you click on any other cell, its 'red' background color will become white or otherwise will loose its previously set background color.

I need that cell to keep its set "red" color background, no matter if user single click on it or anywhere else. I would, if possible, to even disable the single click if that is causing the reset of cells background.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I need that cell to keep its set "red" color background, no matter if user single click on it or anywhere else
I modified the 3 below subs so the background color of cell in column "Name" row 1 will be red no matter where you click on any other cell. It will keep its red color. I hope this is what you are trying to achieve. I tested on your project I have and it worked for me.
B4X:
Private MyBackground As Int  'in Globals

B4X:
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)    
    Dim RowData As Map = B4XTable1.GetRow(RowId)
    Dim cell As String = RowData.Get(ColumnId)
    Activity.Title = cell
    
    Dim cs As CSBuilder
    cs.Initialize.Color(Colors.RGB(0,128,0)).Size(20).Bold.Append(cell).PopAll
    ToastMessageShow(cs, False)
    
    Dim column As B4XTableColumn = B4XTable1.GetColumn("Name")
    Dim pnl As B4XView = column.CellsLayouts.Get(1) 
    Dim l As Label    = pnl.GetView(0)
    l.Color=MyBackground    
End Sub

B4X:
Sub btnNext_Click
    ' **  Modified on purpose ***
    Dim column As B4XTableColumn = B4XTable1.GetColumn("Name")    ' select the column
    markColumnRed(1, column)
    ' make the cell's background colour Red
    Dim pnl As B4XView = column.CellsLayouts.Get(1) 
    Dim l As Label=pnl.GetView(0)
    l.Color=MyBackground
End Sub

B4X:
Sub markColumnRed( RowId As Long, column As B4XTableColumn)
    Dim lightRed As Int= 0xFFFF8F8F   'colour = light Red
    Dim pnl As B4XView = column.CellsLayouts.Get(RowId)
    pnl.color = lightRed
    MyBackground= lightRed
End Sub
 
Upvote 0
Top