So as you can see it start with LAST_ITEM | FIRST_ITEM | SECOND_ITEM
And then incrementing each of three items by one.
This i need for horizontal scroller when i press LEFT Button....When i press RIGHT button it needs to get inverse...
I search forum but could not find function for sort array like i need. I can make it manuall but i like it to calculate thease numbers in example automatically.
I get this code that works as expected but could be short and more faster?
B4X:
'GET - KeyPressed
Sub Activity_KeyPress(KeyCode As Int) As Boolean
'SELECT - Remote Code
Select KeyCode
Case KeyCodes.KEYCODE_DPAD_LEFT
'CHECK - Scrolled
If (Scrolled = 0 Or Scrolled = Items.Length) Then
Log(Items(Items.Length-1))
Log(Items(0))
Log(Items(1))
Scrolled = 1
Else
Log(Items(Scrolled-1))
Log(Items(Scrolled))
If (Scrolled = Items.Length-1) Then
Log(Items(0))
Else
Log(Items(Scrolled+1))
End If
Scrolled = Scrolled + 1
End If
End Select
End Sub
Private Items() As Int = Array As Int (1, 2, 3, 4, 5)
Private Scrolled = 2 As Int
Private ItemsToDisplay = 3 As Int
B4X:
Private i, j As Int
Scrolled = Scrolled + 1
If Scrolled = Items.Length Then
Scrolled = 0
End If
j = Scrolled
For i = 0 To ItemsToDisplay - 1
Log(Items(j))
j = j + 1
If j = Items.Length Then
j = 0
End If
Next
Private Items() As Int = Array As Int (1, 2, 3, 4, 5)
Private Scrolled = 2 As Int
Private ItemsToDisplay = 3 As Int
B4X:
Private i, j As Int
Scrolled = Scrolled + 1
If Scrolled = Items.Length Then
Scrolled = 0
End If
j = Scrolled
For i = 0 To ItemsToDisplay - 1
Log(Items(j))
j = j + 1
If j = Items.Length Then
j = 0
End If
Next
Thanks this fors as expected is short code and really fast...could you update it to get rewerse way too?
I have LEFT and RIGHT buttons so when i press RIGHT button i get this what you write excellent code...now i need to get hen i press LEFTbutton to go back throught array.
I try to change - where is + but i got error..stil traying to archive in minus way.
Private i, j As Int
Scrolled = (Scrolled + 1) Mod Items.Length
j = Scrolled
For i = 0 To ItemsToDisplay - 1
Log(Items(j))
j = (j + 1) Mod Items.Length
Next
Private i, j As Int
Scrolled = (Scrolled + 1) Mod Items.Length
j = Scrolled
For i = 0 To ItemsToDisplay - 1
Log(Items(j))
j = (j + 1) Mod Items.Length
Next
this is shortest and very quck function..thanks....you get
Scrolled + 1 could you write
Scrolled - 1 to get one items back from array? Now it gets one items nex from array