Share My Creation Scroll/Write Dynamic List

Hello to all,

this is the natural continuation of the experiment (already posted here in the forum) to create a dynamic list with possibility to edit its label directly.
Continuing I added at the previous experiment a chance to show and scroll through a text while maintaining the ability to edit the items.

This is what you will find here in a new post, instead of continuing the previous one, in order to avoid possible confusion and to allow further evolutions of the code that became the most complex composition of dynamic objects that work together that i have ever tried to build.
This Is the code (See the notes)
Purple (code to use to transfer the list into a new program)
Black (code used to run the Dynamic List Trial program)
Green (System code notes)
Italic font (note to explain what the code do)
Red (control code line. No need to use in final project)

CODE/ Start

Sub Process_Globals

'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

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 IME As IME
Dim EditText As EditText
Dim P As Panel

Dim Label1 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Label5 As Label
Dim LG As Label
Dim LVNo As Label
Dim Nolbl As EditText

Dim Lista, Nlist, Riga As String
Dim Tx, w, h As Int
Dim Cambio, Nuovo As String
Dim Dati, NewDat As String
Dim Dat(10)
Dim KT, KL, KY As Int
Dim qq As Int
Dim r, i As Int
Dim el As Double
Dim Pag(10)
Dim PagId As Double
Dim Pg, Rdat As Int
Dim Nlbl, rs As Double
Dim No, DD, D1, D2 As Int

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do Not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

Activity.LoadLayout("Main")

Nolbl.inputType = Nolbl.INPUT_TYPE_NUMBERS
Nolbl.Color = Colors.White
Msgbox("Min.2 - Max.9 for this Trial","Select the number of labels")
Dati = "item0|item1|item2|item3|item4|item5|item6|item7|item8|item9|item10|item11|item12|item13|item14|item15|"
End Sub

Sub ConfigRead

No = Dati.Length : Label2.Text = No

For h = 1 To Dati.Length '(to calculate number of items of the text "Dati")
If Dati.CharAt(h-1) = "|" Then el = el + 1
Next


Do Until el <= 0 '(To calculate the pages needed to show text "Dati")
rs = el - Nlbl
PagId = PagId + 1
el = rs
Loop
PagId = Round(PagId)


For s = el To 0 'To create missing items into last Not full)
Dati = Dati & " |"
Next


Lista = Dati '(To create the required pages)
For Pg = 1 To PagId
h = 0
Do Until h = Nlbl
Tx = (Lista).IndexOf("|")
Item = Lista.SubString2(0, Tx)
Pag(Pg) = Pag(Pg) & Item & "|"
Nlist = Lista.SubString2(Tx+1, Lista.Length)
Lista = Nlist
h = h + 1
Loop
Next
Pg = 1
Lista = Pag(Pg)
Crealist
CreaEdit
CreaPan

qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
End Sub

Sub Label4_Click
qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
'Nlbl = Nolbl.Text
Pg = 1
Lista = Pag(Pg)
Crealist
CreaEdit
CreaPan
qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
End Sub

Sub Label3_Click
qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
For kk = 1 To (Pg)
Lista = Lista & Pag(kk)
Next
ClearList
qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
End Sub

Sub Label1_Click
Activity.Finish
End Sub

Sub Crealist 'To create le list of label adding the text of "Dati" string
For y = 0 To Nlbl - 1
Dim L As Label
L.Initialize("Label")
L.Visible = True
L.Color = Colors.White
L.TextSize = LG.TextSize
L.TextColor = Colors.Black
L.SendToBack
Activity.AddView(L,10dip ,Label5.top + y * (LG.Height + 1dip),LG.Width,LG.Height)
L.Gravity = Gravity.CENTER_VERTICAL
Tx = (Lista).IndexOf("|")
LG.Text = Lista.SubString2(0, Tx)
Nlist = Lista.SubString2(Tx+1, Lista.Length) '(remaining Lista string)
Lista = Nlist
L.Text = LG.Text : Dat(y) = L.Text
Next

qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
End Sub

Sub ClearList '(To cancel the dinamically created labels and their text)
For m = qq-1 To 8 Step -1 '(value 8 are the items to not cancel)
Dim L As Label
L.Initialize("Label")
Activity.RemoveViewAt(m)
Next

qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
End Sub

Sub Label_Click '(To export the content of label on click )
Dim L As Label
L.Initialize("Label")
L = Sender
Label2.text = L.Text

End Sub

Sub Label_LongClick '(To active the Edit windows into the selected label)
Cambio = ""
Dim L As Label
L.Initialize("Label")
L = Sender
Cambio = L.Text
KT = L.Top
KL = L.Left
EditText.Top = KT
EditText.Left = KL
EditText.Visible = True
EditText.BringToFront

qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq '(control line)
IME.ShowKeyboard(EditText)
End Sub

Sub EditText_EnterPressed '(Allows to write the edited text into the selected label)
Riga = "" : NewDat = "" :Label2.Text = ""
D1 = Cambio.Length
D2 = (EditText.Text).length
For w = 0 To Nlbl - 1 '4
If Dat(w) = Cambio Then
Dat(w) = EditText.Text
DD = DD + D2 - D1
End If
Riga = Riga & Dat(w) & "|"
Next
Lista = Riga
Pag(Pg) = Riga
EditText.Text = ""
EditText.Top = 50
EditText.Left = 10
EditText.Visible = False
qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq
Crealist
For i = 1 To PagId 'To create the edited Dati string (To save if any)
NewDat = NewDat & Pag(i)
Next
Dati = NewDat.SubString2(0, No+DD)
Label2.text = Dati
qq = Activity.NumberOfViews : LVNo.Text= LVNo.Text & CRLF & qq
IME.HideKeyboard

End Sub

Sub CreaEdit '(To create the dinamic edit text)
Dim E As EditText
E.Initialize("EditText")
E.Visible = True
E.Color = Colors.White
E.TextSize = LG.TextSize - 3
E.TextColor = Colors.Black
E.SingleLine = True
E.SendToBack
E.ForceDoneButton = True
Activity.AddView(E,LG.Left ,Nolbl.Top * (LG.Height + 1dip),LG.Width,LG.Height)
E.Gravity = Gravity.CENTER_VERTICAL
EditText = E

End Sub

Sub CreaPan '(To create the Dynamic Panel)
P.Initialize("P")
Activity.AddView(P, 10dip+LG.Width, Label5.Top, 15dip, (LG.Height * Nlbl)+(Nlbl -1)) '154)
P.Visible = True
P.Enabled = True
P.Color = Colors.White
P.BringToFront

End Sub

Sub P_Touch (Action As Int, X As Float, Y As Float) As Boolean
If Action = Activity.ACTION_DOWN Then
KY = Round(Y)
SelPage
End If

End Sub

Sub SelPage '(to perform the scrolling of text pages)
If KY < P.Height/2 Then
ClearList
Pg = Pg - 1 : If Pg < 1 Then Pg = 1
Lista = Pag(Pg)
Crealist
CreaEdit
CreaPan
Else
ClearList
Pg = Pg + 1 : If Pg > PagId Then Pg = PagId
Lista = Pag(Pg)
Crealist
CreaEdit
CreaPan
End If
Return True

End Sub

Sub Nolbl_EnterPressed
qq = Activity.NumberOfViews
If qq > 8 Then
Return
End If
Nlbl = Nolbl.text
IME.HideKeyboard
ConfigRead
End Sub

CODE/ End

The use of the list allows you to browse (rather than scroll) the text shown in its entirety, allowing you to edit one or more of the labels that compose it, simply by selecting one item with a "Long Click", writing in it editing and using the key (ENTER, Done) to confirm the change.
To scroll the text touch the right side of the list.(top or bottom)
You can clear and recreate the list without loosing the changes until you close the program. (otherwise you can save the string "Dati" in a file)

The code is still subject to changes owing to bugs to fix and/or upgrade.
Known error:
If two fields have the same content by modifying the first one also changes
the other.
Evolution
It must be added the possibility to change the number of labels per page on
users' request. (This also dinamically I.E without restart the program)

Owing to this the file to use by B4a will be posted later. For the moment
you can find here the image of the "main" layout quite easy to reproduce as it
uses only 7 (seven) labels (3 only of which used as buttons have Click event allowed.
Otherwise you find here the apk (zipped) file.

Service Note: The programs runs under GB, ICE, JellyBeam up to 4.2 under which has been tested.
Yo can note that the coordinate to construct labels and other dynamic elements
show clear reference to LG label (Label Guide) or other views in Activity.
This is due to the need to apply the Autosize to the dynamic objects also.
Thanks fo attention.
 

Attachments

  • SWList2013-10-27.png
    SWList2013-10-27.png
    15.9 KB · Views: 3,184
  • SWListA-2013-10-27.png
    SWListA-2013-10-27.png
    26.9 KB · Views: 234
  • SWListB2013-10-27.png
    SWListB2013-10-27.png
    29 KB · Views: 227
  • SWListC2013-10-27_110910.png
    SWListC2013-10-27_110910.png
    16.4 KB · Views: 238
  • MainLayout.png
    MainLayout.png
    6.1 KB · Views: 231
  • listeditor.zip
    107.4 KB · Views: 258
Last edited:

efsoft

Member
Licensed User
Longtime User
A small update.

Hello to all.
a small update to make the test program more easily usable.
As previously indicated:
Solved the problem of managing the string data in order to maintain the correct formatting after changing one or more elements. (therefore with variable length) ..
Added an Edit box to use at startup to choose how many labels should be the page of the list (the list length depends on the data that will be inserted).
It is not the dynamically changing the size of the page as shown above, but at the moment It seems to be a function with unnecessarily cumbersome code.
However, if the code 'List' is used in a program, the variable does not need to be switched on via the Edit Box ..
The code posted and the attached zip file are already updated.
Follow soon other adjustments, and the code to use in B4A.
At the next

Note: To use the program close the messagebox, click on the squared edit text and using the keyboard write a single digit within the requested interval then touch Done/Enter to start the list.
The attached zip file contains the same code of the previous apk but better optimized to use it on tablets.
 

Attachments

  • SWlistStart2013-10-29.png
    SWlistStart2013-10-29.png
    17.3 KB · Views: 230
  • SWlist2013-10-29.png
    SWlist2013-10-29.png
    15.4 KB · Views: 221
  • SWlistLayout.png
    SWlistLayout.png
    7 KB · Views: 195
  • listeditor.zip
    107.4 KB · Views: 208
Last edited:
Top