Code example for LruCache

0
    LruCache<String, Integer>   m_objectPositions;
 
	public ActivityAdapter(ActivityWithAccount ctx) {
		m_cursor = null;
		m_ctx  = ctx;
        m_objectPositions = new LruCache<String, Integer>(20);
	} 
 
    public int findItemById(String id) {
        Integer pos = m_objectPositions.get(id);
        if(pos == null) {
            if(m_cursor == null) return -1;
 
            if(!m_cursor.moveToFirst()) return -1;
            do { 
                String objId = m_cursor.getString(1);
                if(id.equals(objId))
                    return m_cursor.getPosition();
            } while(m_cursor.moveToNext());
            return -1; 
        } else return pos;