ScrollView update button save

angel

Member
Licensed User
Longtime User
:sign0089:Hello

I have a scrollview where I show data from a database, in the layout "principal" in the EditText "EDT2" I write a text, then select the I click the "pnlMed" to select what position I want to update the data i finally pulse the "btnSave" layout "main". The data is saved but the ScrollView does not update until I close or minimize the application. As I can make to save the changes to be updated by pressing the "btnSave".

thanks


'Activity module
Sub Process_Globals
'Aquestes variables globals es va declarar una vegada quan s'inicia l'aplicació.
'Aquestes variables es pot accedir des de tots els mòduls.

' Nom DB, ubicació i noms taules
Dim SQLMedicament As SQL
Dim DBFileName As String : DBFileName = "bebepediatra.db"
'Dim DBFileDir As String : DBFileDir = File.DirInternal
'Dim DBFileDir As String : DBFileDir = File.DirRootExternal
Dim DBFileDir As String : DBFileDir = File.DirDefaultExternal
Dim DBTableNameMedicament As String : DBTableNameMedicament = "medicament"

Dim NumberOfColumns As Int : NumberOfColumns = 6 'IMPORTANT NUMERO COLUMNES
Dim NumberOfRows As Int
Dim ColumnName(NumberOfColumns) As String ' noms de les columnes
ColumnName(0) = "ID_med"
ColumnName(1) = "nom_med"
ColumnName(2) = "descripcio_med"
ColumnName(3) = "contraindicacions_med"
ColumnName(4) = "formula_med"
ColumnName(5) = "caducitat_med"

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 scvMed As ScrollView
Dim PanelHeight As Int : PanelHeight = 160dip
Dim PanelHeight_1 As Int : PanelHeight_1 = PanelHeight - 2dip
Dim pnl1Nb As Int : pnl1Nb=5
Dim edt1, edt2 As EditText
Dim panel1 As Panel
Dim ClickedPanel As Panel

Dim pos As Int

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("inicial")

'File.Delete(DBFileDir, DBFileName) ' used for testing, deletes the existing database
' initilize the database IMPORTANT
If File.Exists(DBFileDir, DBFileName) = False Then
If FirstTime Then
File.Copy(File.DirAssets, DBFileName, DBFileDir, DBFileName)
SQLMedicament.Initialize(DBFileDir, DBFileName, True)
End If
Else
If FirstTime Then
SQLMedicament.Initialize(DBFileDir, DBFileName, True)
End If
End If


End Sub

Sub Activity_Resume
' reads the database
NumberOfRows = 0
SQLTableRead

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub AddRow(Values() As String)
'Adds a row to the table
Dim pnlMed As Panel
pnlMed.Initialize("panel1")
pnlMed.LoadLayout("components")
pnlMed.Color = Colors.Black
pnlMed.Tag = NumberOfRows
scvMed.panel.AddView(pnlMed, 0, 5dip + NumberOfRows * PanelHeight, 100%x, PanelHeight_1)

'LEFT TOP WIDTH HEIGHT

Dim lbl1 As Label
' lbl1 is view 0 in the panel
lbl1 = pnlMed.GetView(0)
lbl1.Tag = NumberOfRows
lbl1.TextSize=20
lbl1.Text = Values(1)

Dim lbl2 As Label
' lbl2 is view 2 in the panel
lbl2 = pnlMed.GetView(1)
lbl2.Tag = NumberOfRows
lbl2.TextSize=20
lbl2.Text = Values(2)


'Dim edt1 As EditText
' edt1 is view 1 in the panel
edt1 = pnlMed.GetView(2)
edt1.Tag = NumberOfRows
edt1.Text = Values(2)


NumberOfRows = NumberOfRows + 1
scvMed.panel.Height = NumberOfRows * PanelHeight


End Sub

Sub SQLTableRead
' Reads the SQL data base
Dim i As Int
Dim Cursor1 As Cursor
Dim txt As String

txt = "SELECT * FROM " & DBTableNameMedicament

Cursor1 = SQLMedicament.ExecQuery(txt)
For i = 0 To Cursor1.RowCount - 1
Dim Col(NumberOfColumns) As String
Cursor1.Position = i
For j = 0 To NumberOfColumns - 1
Col(j) = Cursor1.GetString(ColumnName(j))
Next
AddRow(Col)
Next
Cursor1.Close
Activity.Title = "Bebe Pediatra"
End Sub

Sub btnSave_Click

ClickedPanel.Initialize("")
Dim p As Panel
p.Initialize("")
Dim mapa As Map
mapa.Initialize
mapa.Put("nom_med", pos)
DBUtils.UpdateRecord(SQLMedicament, DBTableNameMedicament, "descripcio_med", edt2.Text , mapa)
Activity.Title ="afdfdfdfd "& (pos)

End Sub


Sub Panel1_Click

ClickedPanel=Sender
Activity.Title ="Tag of clicked panel is "& (ClickedPanel.Tag + 1)
pos = (ClickedPanel.tag + 1 )


End Sub
 
Last edited:

klaus

Expert
Licensed User
Longtime User
It would be easier to help you if you posted your project as a zip file (IDE menu File / Export As Zip). So we could see what you have done and where and test the program in the same conditions as you do. Improvements could be directly added and tested.

' lbl2 is view 2 in the panel
lbl2 = pnlMed.GetView(1)
'edt1 is view 1 in the panel
edt1 = pnlMed.GetView(2)

are these typos 2 - 1 / 1 - 2?

When you add Code in a post please use the code tags.
Click on the # button and put the code between CODE][/CODE.

Best regards.
 
Upvote 0

angel

Member
Licensed User
Longtime User
Hi Klaus

Attached Project, the problem is that the ScrollViewer long as I keep them changes, not Actualized value.

Thanks
 
Upvote 0

angel

Member
Licensed User
Longtime User
perfect thanks, I have done differently, but not if it is correct.

I think I have the solution in "Sub btnSave_Click" I added the two lines of code and updates the ScrollView. If you think there are any mistakes I'd like you to tell me.

NumberOfRows = 0
SQLTableRead

thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It's also a solution.
I think it's not a good idea to reload each time the whole database.

In your code there is one problem.
You call SQLTableRead each time you click on btnSave, so you add new panels each time without removing the previous ones !
If you want to keep your solution you must add code in SQLTableRead to remove all views.

Best regards.
 
Upvote 0
Top