Hi Guys!
I need an help, I've used this code to display scrollview several times but this time I cannot manage to display records in the rows.
The only difference is that in this project I have a 2 tab tabhost and the scrollview is in tab2.
The header is correctly displayed on tab2 but no rows!
Can someone please check my code and give me an hint?
I need an help, I've used this code to display scrollview several times but this time I cannot manage to display records in the rows.
The only difference is that in this project I have a 2 tab tabhost and the scrollview is in tab2.
The header is correctly displayed on tab2 but no rows!
Can someone please check my code and give me an hint?
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim serialechia As String
Dim stringa_SQL As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim SQL1 As SQL :SQL1 = Main.SQL1
Dim TabHost1 As TabHost
Dim CodEse As EditText
Dim FlgPia As EditText
Dim NumPia As EditText
Dim DatPia As EditText
Dim TipDoc As EditText
Dim DesTipDoc As EditText
Dim NumDoc As EditText
Dim AlfDoc As EditText
Dim DatDoc As EditText
Dim CodCon As EditText
Dim RagSoc As EditText
Dim Indirizzo As EditText
Dim Cap As EditText
Dim Comune As EditText
Dim Prov As EditText
Dim TipEva As EditText
Dim DatApp As EditText
Dim CodDes As EditText
Dim OraChi As EditText
Dim RagSocDes As EditText
Dim IndirDes As EditText
Dim CapDes As EditText
Dim ComuneDes As EditText
Dim ProvDes As EditText
Dim TipDdtIng As EditText
Dim NumDdtIng As EditText
Dim AlfDdtIng As EditText
Dim DatDdtIng As EditText
Dim MezChi As EditText
Dim DesMezChi As EditText
Dim DatMez As EditText
Dim OpeMez As EditText
Dim DesOpeMez As EditText
Dim NumMez As EditText
Dim TipInt As EditText
Dim DesTipInt As EditText
Dim TipChi As EditText
Dim DesTipChi As EditText
Dim MotInt As EditText
Dim DatIni As EditText
Dim OraIni As Spinner
Dim DatFin As EditText
Dim OraFin As Spinner
Dim RifChiam As String
' scroll view articoli chiamata
Dim scvList As ScrollView
Dim Header As Panel
Dim Table As Panel
Dim SelectedItems As List
Dim NumberOfRows As Int : NumberOfRows=0
Dim PreviousRow As Int : PreviousRow=-1
Dim NumberOfVisibleRows As Int
Dim NumberOfColumns As Int : NumberOfColumns = 8 'will be overwritten when loading from CscvList file.
Dim RowHeight, RowHeight_1, RowLineWidth As Int
RowLineWidth = 0dip
RowHeight = 30dip
RowHeight_1 = RowHeight - RowLineWidth
Type RowCol (Row As Int, Col As Int)
Dim LineColor As Int : LineColor = Colors.Black
Dim ColumnWidth(8) As Int
Dim ColumnWidth_1(8) As Int
Dim ColLineWidth As Int : ColLineWidth = 0dip
Dim SelectedRowColor As Int : SelectedRowColor=Colors.RGB(250,215,0) 'RGB(255,196,196)
Dim SelectedCellColor As Int : SelectedCellColor=Colors.RGB(250,215,0)
'Table settings
Dim HeaderColor(8) As Int
HeaderColor(0)=Colors.Gray '.RGB(0,255,255)
HeaderColor(1)=Colors.Gray '.RGB(0,255,255)
HeaderColor(2)=Colors.Gray '.RGB(0,160,160)
HeaderColor(3)=Colors.Gray '.RGB(0,160,160)
HeaderColor(4)=Colors.Gray '.RGB(0,160,160)
HeaderColor(5)=Colors.Gray '.RGB(0,160,160)
HeaderColor(6)=Colors.Gray '.RGB(0,160,160)
HeaderColor(7)=Colors.Gray '.RGB(0,160,160)
Dim HeaderFontColor(8) As Int
HeaderFontColor(0)=Colors.White
HeaderFontColor(1)=Colors.White
HeaderFontColor(2)=Colors.White
HeaderFontColor(3)=Colors.White
HeaderFontColor(4)=Colors.White
HeaderFontColor(5)=Colors.White
HeaderFontColor(6)=Colors.White
HeaderFontColor(7)=Colors.White
Dim CellColor(8) As Int
CellColor(0) = Colors.White
CellColor(1) = Colors.White
CellColor(2) = Colors.White
CellColor(3) = Colors.White
CellColor(4) = Colors.White
CellColor(5) = Colors.White
CellColor(6) = Colors.White
CellColor(7) = Colors.White
Dim FontColor(8) As Int
FontColor(0) = Colors.Black
FontColor(1) = Colors.Black
FontColor(2) = Colors.Black
FontColor(3) = Colors.Black
FontColor(4) = Colors.Black
FontColor(5) = Colors.Black
FontColor(6) = Colors.Black
FontColor(7) = Colors.Black
Dim FontSize(8) As Float
FontSize(0) = 13
FontSize(1) = 13
FontSize(2) = 13
FontSize(3) = 13
FontSize(4) = 13
FontSize(5) = 13
FontSize(6) = 13
FontSize(7) = 13
Dim Alignment(8) As Int
Alignment(0) = Gravity.LEFT
Alignment(1) = Gravity.LEFT
Alignment(2) = Gravity.CENTER_HORIZONTAL
Alignment(3) = Gravity.CENTER_HORIZONTAL
Alignment(4) = Gravity.CENTER_HORIZONTAL
Alignment(5) = Gravity.RIGHT
Alignment(6) = Gravity.CENTER_HORIZONTAL
Alignment(7) = Gravity.CENTER_HORIZONTAL
End Sub
Sub Activity_Create(FirstTime As Boolean)
Inizializza
' leggo le righe articolo associate
scvList.Panel.Color=Colors.Black
Table = scvList.Panel
Table.Color = LineColor
ColumnWidth(0) = 0.0 * scvList.Width ' hides the first column
ColumnWidth(1) = 0.05 * scvList.Width ' sets the column widths 1/3 screen width
ColumnWidth(2) = 0.2 * scvList.Width
ColumnWidth(3) = 0.2 * scvList.Width
ColumnWidth(4) = 0.4 * scvList.Width
ColumnWidth(5) = 0.0 * scvList.Width
ColumnWidth(6) = 0.05 * scvList.Width
ColumnWidth(7) = 0.1 * scvList.Width
For i=0 To NumberOfColumns-1
' sets the label width to the column width minus column line width
ColumnWidth_1(i) = ColumnWidth(i)-ColLineWidth
Next
SelectedItems.Initialize
NumberOfVisibleRows=scvList.Height/RowHeight
' leggiamo i record in questione dal db
ClearAll
SQLReadTable
End Sub
Sub Activity_Resume
Inizializza
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
'Disabilita tasto Back
If KeyCode = KeyCodes.KEYCODE_BACK Then
Activity.Finish
StartActivity(RicercaChiamate)
End If
End Sub
Sub DatIni_Click
Dim Dd As DateDialog
Dd.Year = DateTime.GetYear(DateTime.Now)
Dd.Month = DateTime.GetMonth(DateTime.Now)
Dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.Now)
Dim dataDG As Long
ret = Dd.Show("", "Selezionare Data", "", "Conferma", "", LoadBitmap (File.DirAssets, "calendar.png"))
DateTime.DateFormat = "dd/MM/yyyy"
dataDG = Dd.DateTicks
DatIni.Text = DateTime.Date(dataDG)
End Sub
Sub DatFin_Click
Dim Dd As DateDialog
Dd.Year = DateTime.GetYear(DateTime.Now)
Dd.Month = DateTime.GetMonth(DateTime.Now)
Dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.Now)
Dim dataDG As Long
ret = Dd.Show("", "Selezionare Data", "", "Conferma", "", LoadBitmap (File.DirAssets, "calendar.png"))
DateTime.DateFormat = "dd/MM/yyyy"
dataDG = Dd.DateTicks
DatFin.Text = DateTime.Date(dataDG)
End Sub
Sub SetHeader(Values() As String)
' Set the headers values
Dim ColWidth As Int
If Header.IsInitialized Then Return 'should only be called once
Header.Initialize("")
ColWidth=0
For i = 0 To NumberOfColumns - 1
Dim l As Label
l.Initialize("header")
l.Text = Values(i)
l.Gravity = Alignment(i)
l.TextSize = FontSize(i)
l.Color = HeaderColor(i)
l.TextColor = HeaderFontColor(i)
l.Tag = i
Header.AddView(l, ColWidth, 0, ColumnWidth_1(i), RowHeight_1)
ColWidth=ColWidth+ColumnWidth(i)
Next
Activity.AddView(Header, scvList.Left, scvList.Top - RowHeight, scvList.Width, RowHeight)
End Sub
Sub SetCell(Row As Int, Col As Int, Value As String)
' Sets the value of the given cell
GetView(Row, Col).Text = Value
End Sub
Sub AddRow(Values() As String)
' Adds a row to the table
Dim ColWidth As Int
If Values.Length <> NumberOfColumns Then
Log("Wrong number of values.")
Return
End If
ColWidth=0
For i = 0 To NumberOfColumns - 1
Dim l As Label
l.Initialize("cell")
l.Text = Values(i)
l.Gravity = Alignment(i)
l.TextSize = FontSize(i)
l.TextColor = FontColor(i)
l.Color=CellColor(i)
Dim rc As RowCol
rc.Initialize
rc.Col = i
rc.Row = NumberOfRows
l.Tag = rc
Table.AddView(l, ColWidth, RowHeight * NumberOfRows, ColumnWidth_1(i), RowHeight_1)
ColWidth=ColWidth+ColumnWidth(i)
Next
NumberOfRows=NumberOfRows+1
Table.Height = NumberOfRows
End Sub
Sub GetView(Row As Int, Col As Int) As Label
' Returns the label in the specific cell
Dim l As Label
l = Table.GetView(Row * NumberOfColumns + Col)
Return l
End Sub
Sub Cell_Click
Dim rc As RowCol
Dim l As Label
l = Sender
rc = l.Tag
If SelectedItems.Size=1 Then
SelectRow(rc.Row, rc.Col,2)
Else
SelectRow(rc.Row, rc.Col,0)
End If
SelectAdd
End Sub
Sub SelectRow(Row As Int, SelCol As Int, Mode As Int)
' Mode = 0 -> multi selection
' = 1 -> up / down move
' = 2 -> mono selection
Dim col, index As Int
index=SelectedItems.IndexOf(Row) ' tests if the row is alrady selected
If index>-1 Then ' row already selected
For col = 0 To NumberOfColumns - 1
GetView(Row, col).Color = CellColor(col) ' remove the color of previously selected row
Next
SelectedItems.RemoveAt(index) ' removes the row from the list of selected rows
If SelectedItems.Size=1 Then
Row=SelectedItems.Get(0) ' sets row to the last selected row
End If
Else
' adds the selected row to the list and sets the line color
If Mode=0 Then
SelectedItems.Add(Row)
Else If Mode=2 Then
For col = 0 To NumberOfColumns - 1
GetView(PreviousRow, col).Color = CellColor(col) ' sets standard colors to previous row
Next
End If
For col = 0 To NumberOfColumns - 1
GetView(Row, col).Color = SelectedRowColor ' sets selected row colors
Next
End If
If Mode=1 Then ' up / down move
For col = 0 To NumberOfColumns - 1
GetView(PreviousRow, col).Color = CellColor(col)
GetView(Row, col).Color = SelectedRowColor
Next
End If
' update or the Buttons and EditText views
If SelectedItems.Size=1 Then
SelectedItems.Set(0,Row)
PreviousRow=Row
End If
End Sub
Sub SelectAdd
Dim txt As String
'txt="Codes = "
txt=""
For i=0 To SelectedItems.Size-1
If i=0 Then
txt=txt&GetView(SelectedItems.Get(i),0).Text
Else
txt=txt&" / "&GetView(SelectedItems.Get(i),0).Text
End If
Next
Seriale = ""&txt
' Activity.Title = txt
End Sub
Sub ClearAll
Dim i As Int
For i = scvList.Panel.NumberOfViews - 1 To 0 Step -1
scvList.Panel.RemoveViewAt(i)
Next
scvList.Panel.Height = 0
SelectedRow = -1
End Sub
Sub SQLReadTable
' Reads the SQL data base
' Msgbox("SELECT Seriale,NumRig,NumMat,CodiceArt,DesArt,IdArt,Um,Qta from ArtChiamata where RifChiam = '" &RifChiam&"'","")
Dim i As Int
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT Seriale,NumRig,NumMat,CodiceArt,DesArt,IdArt,Um,Qta from ArtChiamata where RifChiam = '" &RifChiam&"'")
Msgbox("SELECT Seriale,NumRig,NumMat,CodiceArt,DesArt,IdArt,Um,Qta from ArtChiamata where RifChiam = '" &RifChiam&"'","")
Dim row(NumberOfColumns) As String
row(0)="Seriale"
row(1)="Riga"
row(2)="Matricola"
row(3)="Codice"
row(4)="Descrizione"
row(5)="IdArt"
row(6)="Um"
row(7)="Qta"
SetHeader(row)
NumberOfRows=0
For i = 0 To Cursor1.RowCount - 1
Dim row(NumberOfColumns) As String
Cursor1.Position = i
Msgbox(""&Cursor1.GetString("DesArt"),"titolo")
row(0)=Cursor1.GetString("Seriale")
row(1)=Cursor1.GetString("NumRig")
row(2)=Cursor1.GetString("NumMat")
row(3)=Cursor1.GetString("CodiceArt")
row(4)=Cursor1.GetString("DesArt")
row(5)=Cursor1.GetString("IdArt")
row(6)=Cursor1.GetString("Um")
row(7)=Cursor1.GetString("Qta")
AddRow(row)
Next
Cursor1.Close
End Sub
Sub Inizializza
Activity.LoadLayout("chiamata")
TabHost1.AddTab("Testata", "chiamata1")
TabHost1.AddTab("Dettaglio", "chiamata2")
' popoliamo gli spinner degli orari
Dim ora As String
For i = 0 To 23
If i < 10 Then
ora = "0"&i
Else
ora = i
End If
OraIni.Add(ora&":00")
OraIni.Add(ora&":15")
OraIni.Add(ora&":30")
OraIni.Add(ora&":45")
'----
OraFin.Add(ora&":00")
OraFin.Add(ora&":15")
OraFin.Add(ora&":30")
OraFin.Add(ora&":45")
Next
If serialechia > 0 Then
Dim cur As Cursor
' cur = SQL1.ExecQuery("SELECT CodEse,FlgPia,NumPia,DatPia,TipDoc,NumDoc,AlfDoc,DatDoc,CodCon,TipEva,DatApp,CodDes,OraChi,TipIng,NumIng,AlfIng,DatIng,MezChi,DatMez,OpeMez,NumMez,TipInt,TipChi,MotInt FROM Chiamate WHERE Seriale ="& "'"&serialechia&"'")
cur = SQL1.ExecQuery("SELECT * FROM Chiamate WHERE Seriale ="& "'"&serialechia&"'")
For i = 0 To cur.RowCount-1
cur.Position = i
CodEse.Text = cur.GetString("CodEse")
If cur.GetString("FlgPia") = "D" Then
FlgPia.Text = "Da Pianificare"
Else
FlgPia.Text = "Pianificata"
End If
NumPia.Text = cur.GetString("NumPia")
DatPia.Text = cur.GetString("DatPia")
TipDoc.Text = cur.GetString("TipDoc")
NumDoc.Text = cur.GetString("NumDoc")
AlfDoc.Text = cur.GetString("AlfDoc")
DatDoc.Text = cur.GetString("DatDoc")
CodCon.Text = cur.GetString("CodCon")
Select cur.GetString("TipEva")
Case "A"
TipEva.Text = "Appuntamento"
Case "P"
TipEva.Text = "Al Passaggio"
Case "U"
TipEva.Text = "Urgente"
End Select
DatApp.Text = cur.GetString("DatApp")
CodDes.Text = cur.GetString("CodDes")
OraChi.Text = cur.GetString("OraChi")
TipDdtIng.Text = cur.GetString("TipIng")
NumDdtIng.Text = cur.GetString("NumIng")
AlfDdtIng.Text = cur.GetString("AlfIng")
DatDdtIng.Text = cur.GetString("DatIng")
MezChi.Text = cur.GetString("MezChi")
DatMez.Text = cur.GetString("DatMez")
OpeMez.Text = cur.GetString("OpeMez")
NumMez.Text = cur.GetString("NumMez")
TipInt.Text = cur.GetString("TipInt")
TipChi.Text = cur.GetString("TipChi")
MotInt.Text = cur.GetString("MotInt")
' impostiamo adesso gli orari di inizio e fine lavoro
DatIni.Text = cur.GetString("DatIni")
' OraIni. = cur.GetString("OraIni")
DatFin.Text = cur.GetString("DatFin")
' OraFin.Text = cur.GetString("OraFin")
' riferimento chiamata per le righe articoli
RifChiam = cur.GetString("CodEse")&cur.GetString("NumDoc")&cur.GetString("AlfDoc")
Next
' leggo adesso le informazioni mancanti sul cliente
cur = SQL1.ExecQuery("SELECT Ragsoc,Indirizzo,Cap,Localita,Prov FROM Clienti WHERE IdCli ='"&CodCon.Text&"'")
For i = 0 To cur.RowCount-1
cur.Position = i
RagSoc.Text = cur.GetString("Ragsoc")
Indirizzo.Text = cur.GetString("Indirizzo")
Cap.Text = cur.GetString("Cap")
Comune.Text = cur.GetString("Localita")
Prov.Text = cur.GetString("Prov")
Next
' leggo adesso l'eventuale destinazione diversa
cur = SQL1.ExecQuery("SELECT RagSocDes,IndirDes,CapDes,LocaliDes,ProvDes FROM DestDive WHERE IdCli ='"&CodCon.Text&"' AND CodDes ='"&CodDes.Text&"'" )
For i = 0 To cur.RowCount-1
cur.Position = i
RagSocDes.Text = cur.GetString("RagSocDes")
IndirDes.Text = cur.GetString("IndirDes")
CapDes.Text = cur.GetString("CapDes")
ComuneDes.Text = cur.GetString("LocaliDes")
ProvDes.Text = cur.GetString("ProvDes")
Next
' leggo adesso il tipo intervento
cur = SQL1.ExecQuery("SELECT DesTipoInt FROM TipiIntervento WHERE TipoInt ='"&TipInt.Text&"'")
For i = 0 To cur.RowCount-1
cur.Position = i
DesTipInt.Text = cur.GetString("DesTipoInt")
Next
' leggo adesso il tipo chiamata
cur = SQL1.ExecQuery("SELECT DesTipoChiam FROM TipiChiamata WHERE TipoChiam ='"&TipChi.Text&"'")
For i = 0 To cur.RowCount-1
cur.Position = i
DesTipChi.Text = cur.GetString("DesTipoChiam")
Next
' leggo adesso il mezzo chiamata
cur = SQL1.ExecQuery("SELECT DesMezzoChiam FROM MezziChiamata WHERE MezzoChiam ='"&MezChi.Text&"'")
For i = 0 To cur.RowCount-1
cur.Position = i
DesMezChi.Text = cur.GetString("DesMezzoChiam")
Next
' leggo adesso l'operatore
cur = SQL1.ExecQuery("SELECT DesOperatore FROM Operatori WHERE Operatore ='"&OpeMez.Text&"'")
For i = 0 To cur.RowCount-1
cur.Position = i
DesOpeMez.Text = cur.GetString("Operatore")
Next
End If
End Sub
Sub TabHost1_TabChanged
' nascondo la scrollview se non sono nella pagina adatta
If TabHost1.CurrentTab = 1 Then
Activity.AddView(Header, scvList.Left, scvList.Top - RowHeight, scvList.Width, RowHeight)
Header.Visible=True
scvList.Visible = True
Else
Header.RemoveView
Header.Visible=False
scvList.Visible = False
End If
End Sub