get Adapter Position By Id - Android android.widget

Android examples for android.widget:Adapter

Description

get Adapter Position By Id

Demo Code

import android.widget.Adapter;
import java.util.NoSuchElementException;

public class Main{

    public static final int getAdapterPositionById(final Adapter adapter,
            final long id) throws NoSuchElementException {
        final int count = adapter.getCount();

        for (int pos = 0; pos < count; pos++) {
            if (id == adapter.getItemId(pos)) {
                return pos;
            }//w  w  w. j ava 2 s .  co m
        }

        throw new NoSuchElementException();
    }

}

Related Tutorials