3

POJO CLASS GridItem:

public class GridItem {

    int id;

    String path;
    String name;
    String chr;
    int headerId;


    public GridItem(String path, String name, String chr){
        this.path = path;
        this.name = name;
        this.chr = chr;
    }
}

In activity:

ArrayList<GridItem> books = new ArrayList<GridItem>(); 

Now i want to convert this arraylist into cursor for making sectionindexer into gridview. so that i use that cursor in below code:

static class YOUR_ADAPTER extends SimpleCursorAdapter implements SectionIndexer {

private AlphabetIndexer mIndexer;

 YOUR_ADAPTER (Context context, AlbumBrowserActivity currentactivity,
            int layout, Cursor cursor, String[] from, int[] to) {
        super(context, layout, cursor, from, to);

        getColumnIndices(cursor);
    } 

    private void getColumnIndices(Cursor cursor) {
        if (cursor != null) {
            YOUR_COLUMN = cursor.getColumnIndexOrThrow(WHAT_YOU'RE_SORTING);

            if (mIndexer != null) {
                mIndexer.setCursor(cursor);
            } else {
                mIndexer = new AlphabetIndexer(cursor, YOUR_COLUMN, mResources.getString(
                        R.string.fast_scroll_alphabet));
            }
        }
    }

 public Object[] getSections() {
        return mIndexer.getSections();
    }

 public int getPositionForSection(int section) {
        return mIndexer.getPositionForSection(section);
    }

 public int getSectionForPosition(int position) {
        return 0;
    }
}

if anyone have solution then make it public here..

6
  • if ArrayList is for data-source then why not creating custom adapter by extending BaseAdapter or ArrayAdapter instead of SimpleCursorAdapter ? Commented Jan 16, 2015 at 6:33
  • i already tried that also.. but sectionindexer is not showing.. Commented Jan 16, 2015 at 6:34
  • see Android ListView with fast scroll and section index which is working with ArrayAdapter Commented Jan 16, 2015 at 6:41
  • @ρяσѕρєяK i already tried that also but didnt work. Commented Jan 16, 2015 at 7:17
  • what problem you are getting? Commented Jan 16, 2015 at 7:18

1 Answer 1

2

You might need to use MatrixCursor, it is a mutable cursor implementation backed by an array of Objects. Use newRow() to add rows. Automatically expands internal capacity as needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.