Android ListView scrolling N Ways

Source: Internet
Author: User

Android inside Let the listview scroll there are n methods, here are listed three kinds:
My requirement is to let the ListView scroll by pressing the button, of course, these keys are not transmitted through the Android identity interface, so it is not possible to monitor the key events to achieve this function;
One, method one:
is also the most commonly used method:

Java code
    1. Listview.setselection (position);


Jump directly to the specified location, can be the event every time the trigger, execute once, to form a scrolling effect;


Two, method two:

Java code
    1. Listview.smoothscrollby ( 200);
    2. Listview.smoothscrolltoposition (index);


Smoothscrolltoposition similar to setselection, but setselection no animation effect, direct jump, smoothscrolltoposition is similar to hand sliding, there is a scrolling process, from the name is smooth meaning ;

Three, method three:
This method is more alternative, generally not used, that is, first let the ListView get the focus, and then inject the upper and lower key events:

Java code
    1. void Sendkey (final int key) {
    2. New Thread () {
    3. public Void Run () {
    4. try {
    5. Instrumentation Inst = new Instrumentation ();
    6. Inst.sendkeydownupsync (key);
    7. } catch (Exception e) {
    8. E.printstacktrace ();
    9. }
    10. }
    11. }.start ();
    12. }

Android ListView scrolling N Ways

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.