Code example for Cursor

Methods: copyStringToBuffergetPositiongetStringmoveToPosition

0
            /* 
             * Separator 
             */ 
            boolean needSeparator = false;
 
            final int position = cursor.getPosition();
            cursor.copyStringToBuffer(AudioFilesQuery.TITLE, holder.titleBuffer);
 
            switch (mCellStates[position]) {
                case STATE_SECTIONED_CELL:
                    needSeparator = true;
                    break; 
 
                case STATE_REGULAR_CELL:
                    needSeparator = false;
                    break; 
 
                case STATE_UNKNOWN:
                default: 
                    // A separator is needed if it's the first itemview of the 
                    // ListView or if the group of the current cell is different 
                    // from the previous itemview. 
                    if (position == 0) {
                        needSeparator = true;
                    } else { 
                        cursor.moveToPosition(position - 1);
 
                        cursor.copyStringToBuffer(AudioFilesQuery.TITLE, mBuffer);
                        if (mBuffer.sizeCopied > 0 && holder.titleBuffer.sizeCopied > 0 && mBuffer.data[0] != holder.titleBuffer.data[0]) {
                            needSeparator = true;
                        } 
 
                        cursor.moveToPosition(position);
                    } 
 
                    // Cache the result 
                    mCellStates[position] = needSeparator ? STATE_SECTIONED_CELL : STATE_REGULAR_CELL;
                    break; 
            } 
 
            if (needSeparator) {
                holder.separator.setText(holder.titleBuffer.data, 0, 1);
                holder.separator.setVisibility(View.VISIBLE);
            } else { 
                holder.separator.setVisibility(View.GONE);
            } 
 
            /* 
             * Title 
             */ 
            holder.titleView.setText(holder.titleBuffer.data, 0, holder.titleBuffer.sizeCopied);
 
            /* 
             * Subtitle 
             */ 
            holder.subtitleBuffer.setLength(0);
            final String album = cursor.getString(AudioFilesQuery.ALBUM);
            if (!TextUtils.isEmpty(album)) {
                holder.subtitleBuffer.append(album);
                final String artist = cursor.getString(AudioFilesQuery.ARTIST);
                if (!TextUtils.isEmpty(artist)) {
                    holder.subtitleBuffer.append(" - ");
                    holder.subtitleBuffer.append(artist);
                } 
            }