Android Question ListView Change SecondLabel On ScrollChange

ronovar

Active Member
Licensed User
Longtime User
I im using ListView and need to when user press UP or DOWN key to change SecondLabel background and ListView Background.

I see that there is no event for ListView_ScrollChanged so is there java function (using java library) to fire up Sub ListView_ScrollChanged so that i can in this sub change background of SecondLabel and ListView Background.

Thanks.
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
B4X:
    Dim jo As JavaObject
    jo=yourlistview
    Dim e As Object =jo.CreateEventFromUI("android.widget.AbsListView.OnScrollListener","list",False)
   
   

    jo.RunMethod("setOnScrollListener", Array As Object(e))

B4X:
Sub list_Event (MethodName As String, Args() As Object) As Object
   
       
    For a = 0 To Args.Length-1
        Log(Args(a))
    Next
   
   
End Sub

You figure out args :D I don't know
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
NIce....i get scolling position...that is excellent...big like! :)

This function extends standard listviews functions to get scrolling position...i get this:

anywheresoftware.b4a.objects.ListViewWrapper$SimpleListView{4245d298 VFED.VC. .F...... 70,82-598,615 #f}

15
153

So to get ScrolledPosition i need just 153 - (15-1) = 139

So position is 13..works like charm.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Ok got another problem:

I declare listview into panel using this code:

B4X:
    'SET - ListViews
    lvChannels.TwoLinesAndBitmap.ItemHeight = 37dip

    'ADDVIEW - Panels
    Activity.AddView(pnlList, 78dip, 82dip, 528dip, 533dip)
   
    'ADDVIEW - ListViews
    pnlList.AddView(lvChannels, 0, 0, 528dip, 535dip)

When i press button PG+ on remote control i get this throught listview:

1
15
29
43
57
71
85
99
113
127
141
------
+14

When i press button PG-on remote control i get this throught listview:

141
125
109
93
77
61
45
29
13
------
-16

So my question is why listview does not scroll equal +/-15 items up and down...does this is bug in native listview control or do i need specify something in B4A code?

I need this because listview work amazing fast and low cpu usage when i im scrolling throught items (cpu usage is < 1%).

So question is: how i need to define listview to scroll using PG+/PG- 15 items down/up?

Thanks.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is B4A project...look at Log when scrolling up and down..i get position 0 and after i click on item5 i get position 1 why is not position 5?

And on another forum i found this to get ListView Y position:

getListView().getChildAt(0).getTop();

how can i do that with javaobject like above example?

Thanks
 

Attachments

  • LVPositions.zip
    7 KB · Views: 299
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Thanks Erel..i try this method that user posted in forum and does not work as expected (first 15items position is 0, next items increment position as it should be, but if you get up in listview counter stays same, so this does not return correct position in listview).

I found in ListView API in android page following function:

B4X:
void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.

It is function of android.widget.ListView adapter.

Could you please Erel or another skilled member write javaobject listener to this function?

This way i will get from this function FOCUS_UP, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_BACKWARD so that i can use this code to get correct position:

B4X:
Select direction
   Case FOCUS_UP
       Position = Position - 1
   Case FOCUS_DOWN
       Position = Position + 1
   Case FOCUS_BACKWARD
       Postion = Position - 15
   Case FOCUS_FORWARD
       Position = Position + 15
End Select

Log("Current ListView Position....."&Position)

I think this will work correctly and precise...ListView Have all 0, 0, 0, 0 positions on first 15items(first scroll page) so it is not implement in andoid api and OS.

Above function i think will work.
 
Upvote 0
Top