Android Question (solved) ADP with multiple pickers

Straker

Active Member
Licensed User
Longtime User
thanks for taking interest , i am also trying it at my end.
the above problem in the screen shot can be removed if you add
layout Variants as
900x600, scale =1(160dp) and remove the phone Variant
regds

Ok, true (I've tested it) so this is not a problem.
Back to your problem:
In order to make your code work you have (it's my opinion) tow options.

** FIRST OPTION **
Just have one adp for each label.
Now you have sDate1, sDate2, sDate3 and so on, but all of these labels are linked to the same adp. Or better, you have only one adp linket to eDate&nt-1. In your for-next cycle you have only one adp, therefore on the last cycle that adp is linked to the last time you used it (eDate & nt-1).
So, you can decare an array of adp -> adp(nt) assigning a single adp to a single label.

*** SECOND OPTION **
If you want to use a single adp you need to link (somehow) the buttons sDateBtn and eDateBtn to the adp.
But you need to know WHICH button has been pressed, in order to link (addToActivity) the unique adp with that specific button.
Now, the button is created by ViewMgr, which uses the Tag property to store a struct (type) with the ActionSub and the calling module. In your case, all the ActionSub are the same (all the 'buttons' raise the same sub sDate_Click or eDate_Click). You can add to the type MyActionSub a new field 'Index' where to store the index of the button (the 'y' of your cycle).
In the sDate_click and eDate_Click events the sender is (I think) a label. So you create a label somewhere (hidden), assign the sender, get the Tag in a struct like your MyActionSub type and use the new .Index property to get the index and then you assign the adp using the Index to correctly point to the destination label....

(hope it works)
 
Upvote 0

sanjibnanda

Active Member
Licensed User
Longtime User
Ok, true (I've tested it) so this is not a problem.
Back to your problem:
In order to make your code work you have (it's my opinion) tow options.

** FIRST OPTION **
Just have one adp for each label.
Now you have sDate1, sDate2, sDate3 and so on, but all of these labels are linked to the same adp. Or better, you have only one adp linket to eDate&nt-1. In your for-next cycle you have only one adp, therefore on the last cycle that adp is linked to the last time you used it (eDate & nt-1).
So, you can decare an array of adp -> adp(nt) assigning a single adp to a single label.

*** SECOND OPTION **
If you want to use a single adp you need to link (somehow) the buttons sDateBtn and eDateBtn to the adp.
But you need to know WHICH button has been pressed, in order to link (addToActivity) the unique adp with that specific button.
Now, the button is created by ViewMgr, which uses the Tag property to store a struct (type) with the ActionSub and the calling module. In your case, all the ActionSub are the same (all the 'buttons' raise the same sub sDate_Click or eDate_Click). You can add to the type MyActionSub a new field 'Index' where to store the index of the button (the 'y' of your cycle).
In the sDate_click and eDate_Click events the sender is (I think) a label. So you create a label somewhere (hidden), assign the sender, get the Tag in a struct like your MyActionSub type and use the new .Index property to get the index and then you assign the adp using the Index to correctly point to the destination label....

(hope it works)

thanks, your second options seems to be more promising as i too thought it and tried and tried it too as in vm class

B4X:
Private Sub Button_Click
Dim myControl As Label
Dim tagActionSub As MyActionSub
'Dim test As Label
'test.Initialize("Tags")
'    test.Tag="look"
'    test = Sender
'    Log(test.Tag)
    myControl = Sender
    tagActionSub = myControl.Tag
    If tagActionSub.IsInitialized Then
        If tagActionSub.ActionSub.Length > 0 Then CallSubDelayed(tagActionSub.ActionSubModule, tagActionSub.ActionSub)
    End If
End Sub

but it seems beyond my skills as could not get it working.
could you see it for rectification, your help will be much appreciated !
regards
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
Well, I'm afraid my skills are lower than yours. Is less than a month that I'm trying B4A.
Butr from what I'm learned the code you posted above probably won't work.


In ViewMgr I changed the Type MyActionSub(ActionSub As String, ActionSubModule As Object, Idx As Int ) -> Idx is added new
In AddButton I added a new parameter 'Index int' and in that sub I set newActionSub.Idx = Index
In the Button_Click I added a line LastTagIdx = tagActionSub.Idx som before the click, I save the Index in the class var LastTagIdx)
(NOTE: I've used Index but maybe it's better use String, as a Tag field)
Then in Class_Globals I added a new variable Private LastTagIdx as Int
And then a Public Sub GetTagIdx() as Int - return LastTagIdx

---- MAIN
Activity_Create



In Main, sDate_Click (and eDate_click) I just added a Log("Index caller=" & VM4.GetTagIdx() )
Then I can check that value to set the adp.AddToActivity(Activity, VM4.GetView("eDate"&y)) where y=index

NOTE: this solution works only with VM4, or only with VM1... I mean that VM1 should raise xDateVM1_Click (and there you can check vm1.GetTagIdx) and VM4 should raise xDateVM4_Click (and you check VM4.GetTagIdx). If you use a single callback for more VM then you don't know which one use in order to retrieve the index)

If you want to use a single callback for all the dates you can simply add a LastTagIdx=0 at the end of the Sub GetTagIdx. So you return the value and then set it to zero, therefore the next call will return zero.
In the single xDate_Click routine you can check VM1.GetTagIdx() and if it zero, check VM4 and so on until you get a valid returned index...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
See this example on how to use two (or more) edittext with ONE adp
 

Attachments

  • twoedittextswithonedatepicker.zip
    12.6 KB · Views: 198
Upvote 0

Straker

Active Member
Licensed User
Longtime User
This is the AdpTest source code modified according to my post #23.
It uses a single adp.
 

Attachments

  • adpTest_singleAdp.zip
    24.2 KB · Views: 183
Upvote 0

sanjibnanda

Active Member
Licensed User
Longtime User
Problem solved !

Thanks to Straker and DonManfred,

Now I have three different solutions!

1) By DonManfred, that uses single adp with different editboxes

2) By Straker , that uses multiple ADP at runtime with view manager by adding extra int parameter to addButton method.

3) And the one (see attachment), fixed by me with Straker's idea of using string (this also uses multiple ADP at runtime with view manager but without adding extra parameter to addButton method via getting string tag.

A special thanks to Erel, for creating a wonderful community where the problems are solved by experts at lightning speed!

thanks again for wonderful support!
 

Attachments

  • adpTest_Fixed.zip
    24.5 KB · Views: 197
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Sanjib, Don, and Straker.

Clever implementation of a much needed consistent Date Picker by Erel. Thank you, Erel.
 
Upvote 0
Top