I have implemented one “up” button and one “down” button in my layout.xml which I want to use in order to navigate through a ListView of strings. How can I accomplish this?
I do not want to use the “scroll” property of the ListView nor to use a LinearLayout with vertical orientation within a Scrollview in order to traverse the list. I simply want to move up and down my ListView by pressing the corresponding buttons.
Any help is appreciated!
You could have a variable
int i = 0;in your class body.Then when the activity loads, the item at location 0 would be selected. If your user presses the down button, then do:
And similarly for going back up:
Of course you’d have to add logic to the code for when you’re already at selection 0 or at the maximum selection, but that’s the gist of how I’d do it.
To note, I’ve never used
ListViewas I’ve not needed to, but the above should work. I got all my information from The Android Documentation