Scroll ListView By Key - Android User Interface

Android examples for User Interface:ListView

Description

Scroll ListView By Key

Demo Code


//package com.java2s;
import android.view.KeyEvent;
import android.widget.ListView;

public class Main {
    public static boolean ScrollListViewByKey(ListView lv, int keyCode) {
        if (lv != null) {
            int offset = (int) (lv.getHeight() * 0.95);
            if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                lv.smoothScrollBy(offset, 500);
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                lv.smoothScrollBy(-1 * offset, 500);
                return true;
            }// ww w.  java2s  .  c o m
        }
        return false;
    }
}

Related Tutorials