Android Question cannot set listview background

cirollo

Active Member
Licensed User
Longtime User
Hi Guys!

I'm getting a strange problem, i cannot set the background color of a list view, infact, when it has no record or after the last record, I get a black color.

The strange thing is that another listview on the same activity gets white when empty or after the last record.

The code of the 2 listviews is identical!!

this is the code, in attached a jpg, the listview is scvlist1

thanx!!!

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 serialecomm 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 Anno As EditText
   Dim IdCommessa As EditText
   Dim DataIni As EditText
   Dim DataFin As EditText
   Dim IdCliente As EditText
   Dim DesCliente As EditText
   Dim Note As EditText
   Dim IdZona As EditText
   Dim DesZona As EditText
   Dim IdAuto As EditText
   Dim DesAuto As EditText
   Dim Targa As EditText
   Dim Ccredito As EditText
   ' DETAIL SQUADRA E AUTOMEZZI
   Dim scvList,scvList1 As ScrollView
   Dim Header,Header1 As Panel
   Dim Table,Table1 As Panel
   Dim SelectedItems,SelectedItems1 As List
   
   Dim NumberOfRows As Int           : NumberOfRows=0
   Dim PreviousRow As Int           : PreviousRow=-1
   Dim NumberOfVisibleRows As Int   
   Dim NumberOfColumns As Int         : NumberOfColumns = 6  'will be overwritten when loading from CscvList file.
   Dim RowHeight, RowHeight_1, RowLineWidth As Int
     RowLineWidth = 0dip
     RowHeight = 18dip
     RowHeight_1 = RowHeight - RowLineWidth
   
   'Type RowCol (Row As Int, Col As Int)
   Dim LineColor  As Int           : LineColor = Colors.Black
   Dim ColumnWidth(6) As Int
   Dim ColumnWidth_1(6) 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(6) 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)
     
   Dim HeaderFontColor(6) 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
       
   Dim CellColor(6) 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
   
   Dim FontColor(6) 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
     
   Dim FontSize(6) As Float
     FontSize(0) = 13
     FontSize(1) = 13
     FontSize(2) = 13
     FontSize(3) = 13
     FontSize(4) = 13
     FontSize(5) = 13
   
   Dim Alignment(6) As Int
     Alignment(0) = Gravity.LEFT
     Alignment(1) = Gravity.LEFT
     Alignment(2) = Gravity.LEFT
     Alignment(3) = Gravity.LEFT
     Alignment(4) = Gravity.CENTER_HORIZONTAL
     Alignment(5) = Gravity.CENTER_HORIZONTAL

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Inizializza
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   
  Return True   
  Else
  Return False
  End If
End Sub

Sub Inizializza
   Activity.LoadLayout("commessa")
   If serialecomm <> "" Then
     Dim Cur As Cursor
     Cur = SQL1.ExecQuery("SELECT * FROM Commesse WHERE IdCommessa ="& "'"&serialecomm&"'")
     For i = 0 To Cur.RowCount-1
         Cur.Position = i
       Anno.Text = Cur.GetString("Anno")
       IdCommessa.Text = Cur.GetString("IdCommessa")
       DataIni.Text = Cur.GetString("DataIni")
       DataFin.Text = Cur.GetString("DataFin")
       IdCliente.Text = Cur.GetString("IdCliente")
       DesCliente.Text = Cur.GetString("DesCliente")
       IdZona.Text = Cur.GetString("IdZona")
       DesZona.Text = Cur.GetString("DesZona")
     Next
     ' leggo adesso le informazioni mancanti sul cliente
   '   cur = SQL1.ExecQuery("SELECT Ragsoc,Indirizzo,Cap,Localita,Prov,Telefono,Mobile 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")
   '     TelCli.Text = cur.GetString("Telefono")
   '     CelCli.Text = cur.GetString("Mobile")
   '   Next
     ' POPOLIAMO IL DETAIL SQUADRA
     scvList.Panel.Color=Colors.Black
     Table = scvList.Panel
     Table.Color = LineColor
     ColumnWidth(0) = 0.1 * scvList.Width     ' sets the column widths 1/3 screen width
     ColumnWidth(1) = 0.25 * scvList.Width
     ColumnWidth(2) = 0.1 * scvList.Width
     ColumnWidth(3) = 0.25 * scvList.Width
     ColumnWidth(4) = 0.15 * scvList.Width
     ColumnWidth(5) = 0.15 * 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
     
     Dim Cur As Cursor
     Cur = SQL1.ExecQuery("select * from Squadra where IdCommessa = '"&IdCommessa.Text&"'")
     Dim row(NumberOfColumns) As String
     row(0)="Id Dip."
     row(1)="Nominativo"
     row(2)="Mansione"
     row(3)="Descrizione"
     row(4)="Data Inizio"
     row(5)="Data Fine"
     SetHeader(row)
     NumberOfRows=0
     For i = 0 To Cur.RowCount - 1
       Dim row(NumberOfColumns) As String
       Cur.Position = i
       row(0)=Cur.GetString("IdDipen")
       row(1)=Cur.GetString("DesDipen")
       row(2)=Cur.GetString("IdMansione")
       row(3)=Cur.GetString("DesMansione")
       row(4)=Cur.GetString("DataIni")
       row(5)=Cur.GetString("DataFin")
       AddRow(row)
     Next
     Cur.Close
   
     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
   
     ' POPOLIAMO IL DETAIL AUTOMEZZI COMMESSA
     scvList1.Panel.Color=Colors.Black
     Table1 = scvList1.Panel
     Table1.Color = LineColor
     ColumnWidth(0) = 0.1 * scvList1.Width     ' sets the column widths 1/3 screen width
     ColumnWidth(1) = 0.25 * scvList1.Width
     ColumnWidth(2) = 0.1 * scvList1.Width
     ColumnWidth(3) = 0.25 * scvList1.Width
     ColumnWidth(4) = 0.15 * scvList1.Width
     ColumnWidth(5) = 0.15 * scvList1.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
     SelectedItems1.Initialize
     
     Dim Cur As Cursor
     Cur = SQL1.ExecQuery("select * from Autocomm where IdCommessa = '"&IdCommessa.Text&"'")
     Dim row(NumberOfColumns) As String
     row(0)="Id Auto"
     row(1)="Descrizione"
     row(2)="Targa"
     row(3)="Carta Carburante"
     row(4)="Data Inizio"
     row(5)="Data Fine"
     SetHeader1(row)
     NumberOfRows=0
     For i = 0 To Cur.RowCount - 1
       Dim row(NumberOfColumns) As String
       Cur.Position = i
       row(0)=Cur.GetString("IdAuto")
       row(1)=Cur.GetString("DesAuto")
       row(2)=Cur.GetString("Targa")
       row(3)=Cur.GetString("CCredito")
       row(4)=Cur.GetString("DataIni")
       row(5)=Cur.GetString("DataFin")
       AddRow1(row)
     Next
     Cur.Close
   
     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
   
   End If
End Sub

Sub BtnOrari_Click
   Dim result As Int
   result = Msgbox2("Confermi Compilazione Orari?", Main.nomeprog, "Si", "", "No",LoadBitmap (File.DirAssets, "warning_small.png"))
   If result = DialogResponse.Positive Then
     StartActivity(Orari)
   End If
End Sub

Sub BtnEsc_Click   
   Dim result As Int
   result = Msgbox2("Confermi Uscita Commessa?", Main.nomeprog, "Si", "", "No",LoadBitmap (File.DirAssets, "warning_small.png"))
   If result = DialogResponse.Positive Then
     Activity.Finish
     StartActivity(RicercaCommesse)
   End If
End Sub

Sub SetHeader(Values() As String)
   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 SetHeader1(Values() As String)
   Dim ColWidth As Int
   If Header1.IsInitialized Then Return 'should only be called once
   Header1.Initialize("")
   ColWidth=0
   For I = 0 To NumberOfColumns - 1
     Dim l As Label
     l.Initialize("header1")
     l.Text = Values(I)
     l.Gravity = Alignment(I)
     l.TextSize = FontSize(I)
     l.Color = HeaderColor(I)
     l.TextColor = HeaderFontColor(I)
     l.Tag = I
     Header1.AddView(l, ColWidth, 0, ColumnWidth_1(I), RowHeight_1)
     ColWidth=ColWidth+ColumnWidth(I)
   Next
   Activity.AddView(Header1, scvList1.Left, scvList1.Top - RowHeight, scvList1.Width, RowHeight)
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 * RowHeight
End Sub

Sub AddRow1(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
     Table1.AddView(l, ColWidth, RowHeight * NumberOfRows, ColumnWidth_1(I), RowHeight_1)
     ColWidth=ColWidth+ColumnWidth(I)
   Next
   NumberOfRows=NumberOfRows+1
   Table1.Height = NumberOfRows * RowHeight
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 GetView1(Row As Int, Col As Int) As Label
' Returns the label in the specific cell
   Dim l As Label
   l = Table1.GetView(Row * NumberOfColumns + Col)
   Return l
End Sub

Sub BtnCosti_Click
   Dim result As Int
   result = Msgbox2("Confermi Compilazione Costi?", Main.nomeprog, "Si", "", "No",LoadBitmap (File.DirAssets, "warning_small.png"))
   If result = DialogResponse.Positive Then
     StartActivity(Costi)
   End If
End Sub
 

Attachments

  • IMG_20131123_140408.jpg
    IMG_20131123_140408.jpg
    112.1 KB · Views: 270

cirollo

Active Member
Licensed User
Longtime User
Erel,

the code necessary to display listview is all in that activity module....
I use two listviews with same settings (font, header color, ....) but with different data (takne with queries on two tables)
I think the problem should be in the setheader1 sub (for listview1 with problem) but its the same as setheader (for listview without problem)
 
Upvote 0
Top