Android Question How to remove binding KeyCode DPAD_DOWN and UP from the CLV scroll event?

teddybear

Well-Known Member
Licensed User
I want to select a item of CLV using DPAD ,When the items are created , using DPAD up or down it works fine, but after I hide the CLV and then show it again, the DPAD UP and DOWN are bound to the CLV scroll event,Icould not catch UP and DOWN keycodes utill CLV scrolls to Top or Bottom.

The code is :
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private cs1 As CLVSelections
    Private Clv1 As CustomListView
    Private item_no As Int = 10

End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Clv1.clear
    Log(Clv1.sv.Visible)
    For i = 0 To 20
        Clv1.AddTextItem("Item#"&i, i)
    Next
    If cs1.IsInitialized = False  Then
        cs1.Initialize(Clv1)
    End If

    cs1.Mode = cs1.MODE_SINGLE_ITEM_PERMANENT
    cs1.VisibleRangeChanged(0,20)
    cs1.ItemClicked(item_no)
    Sleep(200)
    cs1.SelectAndMakeVisible(item_no)

End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub B4XPage_KeyPress(KeyCode As Int)

    Select KeyCode   
        Case KeyCodes.KEYCODE_DPAD_DOWN
            If item_no < 20 Then
                item_no = item_no + 1
                cs1.ItemClicked(item_no)
                Sleep(200)
                cs1.SelectAndMakeVisible(item_no)
            End If
        Case KeyCodes.KEYCODE_DPAD_UP
            If item_no > 0 Then
                item_no = item_no - 1
                cs1.ItemClicked(item_no)
                Sleep(200)
                cs1.SelectAndMakeVisible(item_no)
            End If
        Case KeyCodes.KEYCODE_DPAD_LEFT
                Clv1.sv.Visible = False
        Case KeyCodes.KEYCODE_DPAD_RIGHT
                Clv1.sv.Visible = True
    
    End Select

End Sub
 
Top