R ronovar Active Member Licensed User Longtime User Apr 6, 2016 #1 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.
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 Apr 6, 2016 #2 Code: Copy 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)) Code: Copy 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 I don't know Upvote 0
Code: Copy 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)) Code: Copy 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 I don't know
R ronovar Active Member Licensed User Longtime User Apr 6, 2016 #3 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
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.
R ronovar Active Member Licensed User Longtime User Apr 7, 2016 #4 Ok got another problem: I declare listview into panel using this code: Code: Copy '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
Ok got another problem: I declare listview into panel using this code: Code: Copy '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.
R ronovar Active Member Licensed User Longtime User Apr 8, 2016 #5 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 LVPositions.zip 7 KB · Views: 573 Upvote 0
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
R ronovar Active Member Licensed User Longtime User Apr 10, 2016 #6 I have found one more suggestion if someone can try this and how to get this using javaobject or reflector runmethod2 getListView().getChildAt(0).getTop(); http://stackoverflow.com/questions/12727594/android-listview-current-scroll-location-y-pixels Upvote 0
I have found one more suggestion if someone can try this and how to get this using javaobject or reflector runmethod2 getListView().getChildAt(0).getTop(); http://stackoverflow.com/questions/12727594/android-listview-current-scroll-location-y-pixels
Erel B4X founder Staff member Licensed User Longtime User Apr 10, 2016 #7 You can call it with JavaObject: Code: Copy Dim jo As JavaObject= ListView1 Dim top As Int = jo.RunMethodJO("getChildAt", Array(0)).RunMethod("getTop", Null) I recommend you to switch to CustomListView, unless you are showing many items (1000+). Upvote 0
You can call it with JavaObject: Code: Copy Dim jo As JavaObject= ListView1 Dim top As Int = jo.RunMethodJO("getChildAt", Array(0)).RunMethod("getTop", Null) I recommend you to switch to CustomListView, unless you are showing many items (1000+).
R ronovar Active Member Licensed User Longtime User Apr 15, 2016 #8 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: Code: Copy 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: Code: Copy 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
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: Code: Copy 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: Code: Copy 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.