Example usage for android.widget GridView setSelectionFromTop

List of usage examples for android.widget GridView setSelectionFromTop

Introduction

In this page you can find the example usage for android.widget GridView setSelectionFromTop.

Prototype

public void setSelectionFromTop(int position, int y) 

Source Link

Document

Sets the selected item and positions the selection y pixels from the top edge of the ListView.

Usage

From source file:Main.java

/**
 * Scrolls a specific grid view to the item at a specific index.
 *
 * @param gridView/* www  . j  a  v a2s .c om*/
 *         The grid view, which should be scrolled, as an instance of the class {@link
 *         GridView}. The grid view may not be null
 * @param index
 *         The index of the item, the grid view should be scrolled to, as an {@link Integer}
 *         value
 * @param offset
 *         The offset of the item, the grid view should be scrolled to, as an {@link Integer}
 *         value
 */
private static void scrollTo(@NonNull final GridView gridView, final int index, final int offset) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        gridView.setSelectionFromTop(index, offset);
    } else {
        gridView.setSelection(index);
    }
}