i want to create a some array of buttons during the job done function, from my knowledge i don't think its possible to create button outside of Activity_Create, is i have to call activity create function from job done, in that case how can i set the text for array of buttons (i mean can i pass parameter in activity create function), or else hope some other way we can create button array from job done, pls guide me, thanks in advance
Why? You can create any view when and where you need.
At least you will have to declare an Array or List or Map in the Globals to "hold" the new views.
Create a Sub to add a new view, like:
B4X:
Sub AddNewButton(pnlParent As Panel, EventName As String, Left As Int, Top As Int, Width As Int, Height As Int, Text As String) As Button
Dim btn As Button
btn.Initialize(EventName)
pnlParent.AddView(btn, Left, Top, Width, Height)
btn.Text = Text
Return btn
End Sub
Hi Sofiya,
You can create an array of Buttons, like this:
B4X:
Dim Buttons() as Button
Later on, you can access, initialize and customize each individual button through its index:
B4X:
Buttons(0).Initialize("Buttons")
Buttons(0).Tag = 0 'This is to identify whichbutton was clicked
Buttons(0).Color=...
Buttons(0).whatever...
Activity.AddView(Buttons(0), Left, Top, Width, Height)
And so on...
To catch click event, use Sender
B4X:
Sub Buttons_Click
Dim b as Button = Sender
Select b.tag 'Which button was clicked?
Case 0
Whatever code Button(0) should execute
Case 1
Whatever code Button(1) should execute
...
End Select
End Sub
At least you will have to declare an Array or List or Map in the Globals to "hold" the new views.
Create a Sub to add a new view, like:
B4X:
Sub AddNewButton(pnlParent As Panel, EventName As String, Left As Int, Top As Int, Width As Int, Height As Int, Text As String) As Button
Dim btn As Button
btn.Initialize(EventName)
pnlParent.AddView(btn, Left, Top, Width, Height)
btn.Text = Text
Return btn
End Sub
At least you will have to declare an Array or List or Map in the Globals to "hold" the new views.
Create a Sub to add a new view, like:
B4X:
Sub AddNewButton(pnlParent As Panel, EventName As String, Left As Int, Top As Int, Width As Int, Height As Int, Text As String) As Button
Dim btn As Button
btn.Initialize(EventName)
pnlParent.AddView(btn, Left, Top, Width, Height)
btn.Text = Text
Return btn
End Sub
Use the "Tag" property to store the name/id of the button. Of course you'll have to loop through the views in order to find the button of interest. Best thing is use a prefix for all your button names e.g "btnButton1". This way when you loop through the views you can ignore any that don't begin with "btn" thus saving some time.
Why? You can create any view when and where you need.
At least you will have to declare an Array or List or Map in the Globals to "hold" the new views.
Create a Sub to add a new view, like:
B4X:
Sub AddNewButton(pnlParent As Panel, EventName As String, Left As Int, Top As Int, Width As Int, Height As Int, Text As String, ID as String) As Button
Dim btn As Button
btn.Initialize(EventName)
pnlParent.AddView(btn, Left, Top, Width, Height)
btn.Text = Text
btn.Tag = ID '<<<<< add this line
Return btn
End Sub
can u please tell me what event name should i use in the place of event name parameter, because i use the event name i.e. lstButtons_click but it's not work.
B4X:
Sub JobDone (job1 As HttpJob)
Log("JobName = " & job1.JobName & ", Success = " & job1.Success)
ProgressDialogHide
' Job.GetRequest.Timeout = 60000
If job1.Success Then
Select job1.JobName
Case "Outlet"
' Log(job1.GetString)
Dim parser As JSONParser
Dim response As String = job1.GetString
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
Log("posname=" & m.Get("posname"))
Log("poscode=" & m.Get("poscode"))
lstButtons.Initialize
lstButtons.Add(AddNewButton(Activity, "lstButtons_Click", 100dip, 40dip + 60dip * i, 120dip, 50dip, m.Get("posname")))
' StartActivity(Table)
Next
End Select
End If
job1.Release
End Sub
Sub lstButtons_Click
Dim b As Button = Sender
b.Text = ""
StartActivity(Table)
End Sub
can u please tell me what event name should i use in the place of event name parameter, because i use the event name i.e. lstButtons_click but it's not work.