Android Question B4XTable FullRowSelect?

Status
Not open for further replies.

mangojack

Expert
Licensed User
Longtime User
Are you wanting all row values returned following a row cell click ?
This is already done via a Map containing all row cell value's ... just read the map.

From the B4X Table example,
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
    Log("US County")
    Log(RowData.Get("Interesting Number"))
    Log(RowData.Get("Name"))
    Log(RowData.Get("State"))
End Sub


OR .. are you wanting the entire row Selected / Colored on row cell click ??

This might help https://www.b4x.com/android/forum/threads/b4x-b4xtable-multiple-rows-selection.102364/

Cheers
 
Last edited:
Upvote 0

Marlou Fin

Member
Licensed User
Hi Mangojack,

The entire full row select same what we have for table view. Cause right now when you click a cell, the highlight was gone after you click the cell.

Thanks,
Marlou
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
You could try something like this .. Only gave it a quick test.

Firstly .. in the designer you must set the Selected Color to Transparent.

Global Var's ..
B4X:
Private SelectionColor As Int = 0xFF009DFF 
Private LastSelection As Int

B4X:
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
         
    Dim Index As Int = B4XTable1.VisibleRowIds.IndexOf(RowId) 
    SetRowColor(Index)
    LastSelection = Index
 
    'more code ............................. 
End Sub

Sub SetRowColor(RowIndex As Int)
       
  'recolor previous selection
    Dim clr As Int
    If LastSelection Mod 2 = 0 Then
        clr = B4XTable1.EvenRowColor
    Else
        clr = B4XTable1.OddRowColor
    End If
 
    For Each c As B4XTableColumn In B4XTable1.VisibleColumns
        Dim pnl As B4XView = c.CellsLayouts.Get(LastSelection+ 1) '+1 because of the header
        pnl.Color = clr
    Next
 
'color current selected row
    For Each c As B4XTableColumn In B4XTable1.VisibleColumns
        Dim pnl As B4XView = c.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
        pnl.Color = SelectionColor
    Next
 
End Sub
 
Upvote 0

Marlou Fin

Member
Licensed User
Hi Mangojack,

Follow up question for B4XTable. How can we set the text alignement of the table.

I tried the B4XTable1.mBase.SetTextAlignment("TOP","LEFT") but getting this error below.

Error occurred on line: 93 (Customer_Form)
java.lang.RuntimeException: Type does not match (class anywheresoftware.b4a.BALayout)
at anywheresoftware.b4a.objects.B4XViewWrapper.typeDoesNotMatch(B4XViewWrapper.java:361)
at anywheresoftware.b4a.objects.B4XViewWrapper.asLabelWrapper(B4XViewWrapper.java:193)
at anywheresoftware.b4a.objects.B4XViewWrapper.SetTextAlignment(B4XViewWrapper.java:262)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
(Exception) java.lang.Exception: java.lang.RuntimeException: Type does not match (class anywheresoftware.b4a.BALayout)
 
Upvote 0
Status
Not open for further replies.
Top