Android Question B4XPlusMinus View Decrement or Increment

bocker77

Active Member
Licensed User
Longtime User
I cannot find a way to determine if the integer value in a B4XPlusMinus view was incremented or decremented. I would like to be able to do this in the ValueChanged event. I have been spinning my wheels in the Forum to see if anyone else was able to do this. Tried a few things in my code with the view but am getting nowhere. I thought maybe I could use the pnlMinus and pnlPlus to determine what was pressed. Any help would be appreciated.
 

bocker77

Active Member
Licensed User
Longtime User
Thanks for responding. According to your response the answer is "No" you can't. My problem is that I have a list with over 20 of these views with each value there is a number that needs to be calculated. Also the user is given an amount where I want to let them know if they are going over it. This will require multiple variables and calculations where if I could tell if it was an increment or decrement I would only need one variable.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPlusMinus1.SetNumericRange(0, 100, 1)
    B4XPlusMinus1.Tag = 0
End Sub

Private Sub B4XPlusMinus1_ValueChanged (Value As Object)
    Dim PlusMinus As B4XPlusMinus = Sender
    Dim previousValue As Int = PlusMinus.Tag
    If Value.As(Int) > previousValue Then
        Log("Incremented")
    Else if Value.As(Int) < previousValue Then
        Log("Decremented")
    End If
    PlusMinus.Tag = Value
End Sub
 
Last edited:
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Thanks William but I am already using the tag to indicate which of the many views is having the value changed.

B4X:
    ' Load Purchasing screen
    Dim SenderFilter As Object = sqlDB.ExecQueryAsync("SQL", "SELECT * FROM Purchasing", Null)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
    If Success Then
        Dim iTag As Int = 1
        Do While rs.NextRow
            Dim PurchaseItem As typPurchase
            PurchaseItem.UnitName = rs.GetString("unitname")
' cost = 30, 12, 15, 15, 3, 4, 4, 6, 5, 10, 11, 12, 20, 16, 12, 8, 6, 7
            PurchaseItem.Cost = rs.GetString("cost")
            lsvPurchasing.Add(CreatePurItem(iTag, lsvPurchasing.AsView.Width, 70dip), PurchaseItem)
            mapIPCExpended.Put(iTag, PurchaseItem.Cost)
            iTag = iTag + 1
        Loop
        rs.Close
    Else
        Log(LastException)
    End If
...
Sub Purchasing_ValueChanged(Value As Object)
    Dim pm As B4XPlusMinus = Sender
    If *increment* Then
         iIPCExpended = iIPCExpended + mapIPCExpended.Get(pm.Tag)
    Else If *decrement* Then
         iIPCExpended = iIPCExpended - mapIPCExpended.Get(pm.Tag)
    End If
    lblIPCExpended.Text = iIPCExpended 
End Sub

It looks since I can't determine the difference then I am going to have more code, variables, and calculations for something so simple.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Or even an Array.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPlusMinus1.SetNumericRange(0, 100, 1)
    B4XPlusMinus1.Tag = Array("Button 1", 0)
End Sub

Private Sub B4XPlusMinus1_ValueChanged (Value As Object)
    Dim PlusMinus As B4XPlusMinus = Sender
    Dim ar() As Object = PlusMinus.Tag
    If Value.As(Int) > ar(1).As(Int) Then
        Log(ar(0) & ": Incremented")
    Else if Value.As(Int) < ar(1).As(Int) Then
        Log(ar(0) & ": Decremented")
    End If
    ar(1) = Value
End Sub
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
William, your code looks promising. I will play around with it and see what I get. In the meantime I came up with this which is not quite what I would like to do but it will work.

B4X:
Sub Purchasing_ValueChanged(Value As Object)
    Dim iValue As Int = Value
    Dim pm As B4XPlusMinus = Sender
    mapIPCExpended.Put(pm.Tag, iValue)
End Sub

Private Sub btnPurDone_Click
    For i = 0 To mapIPCCosts.Size - 1
        iIPCExpended = iIPCExpended + (mapIPCCosts.Get(i) * mapIPCExpended.Get(i))            
    Next
End Sub
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
And with all of your help I think I can come up with something. If any of you want to know what I decided on let me know.

Thanks to all of you for taking the time to help!
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Lo and behold I stumbled across the AS_PlusMinus library provided by Alexander Stolte which does exactly what I need. It has separate events for minus and plus. I will be testing with this library. If I found this earlier I would not have created this post. But thanks again to all that responded with your suggestions.
 
Upvote 0
Top