Android Question Bring forward, Send backward [Solved]

Roger Daley

Well-Known Member
Licensed User
Hi All,

I am looking for a way to programmatically send an Edittext backward or bring forward on the Views Tree as opposed to Edt.Bringtofront? I have found a wish for this on the forum but no answer.

Any hint gratefully received.

Regards Roger
 
Last edited:

lucasheer

Member
Licensed User
B4X:
Sub sendViewBackwards(v As B4XView, p As Pane)
    Dim found As Int = -1
    For i=0 To p.NumberOfNodes
        Dim b As B4XView = p.GetNode(i)
        If(b = v) Then
            found = i
            Exit
        End If
    Next
    
    If(found > 0) Then
        v.SendToBack
        For i=0 To found -1
            Dim b As B4XView = p.GetNode(i)
            b.sendtoback
        Next
    End If
End Sub

Sub sendViewForwards(v As B4XView, p As Pane)
    Dim found As Int = -1
    For i=0 To p.NumberOfNodes
        Dim b As B4XView = p.GetNode(i)
        If(b = v) Then
            found = i
            Exit
        End If
    Next
    
    If(found < p.NumberOfNodes - 1) Then
        v.BringToFront
        For i=0 To p.NumberOfNodes - found - 1
            Dim b As B4XView = p.GetNode(found)
            b.BringToFront
        Next
    End If
End Sub
I wrote this in B4J.

You can use these functions to send a specific view in a panel forwards or backwards.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
B4XView version of this code:
B4X:
Sub sendViewBackwards(v As B4XView, p As B4XView)
    Dim found As Int = -1
    For i=0 To p.NumberOfViews
        Dim b As B4XView = p.GetView(i)
        If(b = v) Then
            found = i
            Exit
        End If
    Next
    
    If(found > 0) Then
        v.SendToBack
        For i=0 To found -1
            Dim b As B4XView = p.GetView(i)
            b.sendtoback
        Next
    End If
End Sub

Sub sendViewForwards(v As B4XView, p As B4XView)
    Dim found As Int = -1
    For i=0 To p.NumberOfViews
        Dim b As B4XView = p.GetView(i)
        If(b = v) Then
            found = i
            Exit
        End If
    Next
    
    If(found < p.NumberOfViews - 1) Then
        v.BringToFront
        For i=0 To p.NumberOfViews - found - 1
            Dim b As B4XView = p.GetView(found)
            b.BringToFront
        Next
    End If
End Sub
Tip: never use Pane.
 

Roger Daley

Well-Known Member
Licensed User
B4X:
Sub sendViewBackwards(v As B4XView, p As Pane)
    Dim found As Int = -1
    For i=0 To p.NumberOfNodes
        Dim b As B4XView = p.GetNode(i)
        If(b = v) Then
            found = i
            Exit
        End If
    Next
    
    If(found > 0) Then
        v.SendToBack
        For i=0 To found -1
            Dim b As B4XView = p.GetNode(i)
            b.sendtoback
        Next
    End If
End Sub

Sub sendViewForwards(v As B4XView, p As Pane)
    Dim found As Int = -1
    For i=0 To p.NumberOfNodes
        Dim b As B4XView = p.GetNode(i)
        If(b = v) Then
            found = i
            Exit
        End If
    Next
    
    If(found < p.NumberOfNodes - 1) Then
        v.BringToFront
        For i=0 To p.NumberOfNodes - found - 1
            Dim b As B4XView = p.GetNode(found)
            b.BringToFront
        Next
    End If
End Sub
I wrote this in B4J.

You can use these functions to send a specific view in a panel forwards or backwards.
Thanks Erel,
I'll see what I can do in B4A.

Roger
 

Roger Daley

Well-Known Member
Licensed User
CONTINUED IN THIS THREAD.

 
Top