在android中将对象arraylist转换为光标
POJO类GridItem:在android中将对象arraylist转换为光标,android,arraylist,pojo,android-cursor,Android,Arraylist,Pojo,Android Cursor,POJO类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
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;
}
}
在活动中:
ArrayList<GridItem> books = new ArrayList<GridItem>();
如果任何人有解决方案,请在此处公开。您可能需要使用它,它是一个由对象数组支持的可变游标实现。使用newRow()添加行。根据需要自动扩展内部容量。如果
ArrayList
用于数据源,那么为什么不通过扩展BaseAdapter
或ArrayAdapter
而不是SimpleCursorAdapter
,来创建自定义适配器呢?我已经尝试过了。。但是sectionindexer没有显示..看哪一个与ArrayAdapter@ρаσѕρєK一起工作我也试过了,但没有工作。你遇到了什么问题?
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;
}
}