问题
I've used list fragment and list view for displaying manufacture items. For that I've created a manufacture adapter for list out the items and it list more than hundred items. Now My requirement is to show the mostly frequently selected items( three items more enough) at the top of list.
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ManufacturerListAdapter adapter = (ManufacturerListAdapter) getListAdapter();
Cursor cursor = (Cursor) adapter.getItem(position);
String manufacturerId = cursor.getString(cursor.getColumnIndex(ManufacturersColumns.MANUFACTURER_ID));
int isUserCreated = cursor.getInt(cursor.getColumnIndex("usergen"));
EditableItemActivity activity = (EditableItemActivity) getActivity();
if (activity != null) activity.setManufacturer(manufacturerId, isUserCreated > 0);
hideKeyboard();
}
});
I added a snippet of on click event of listed items. Hope it will more helpful to understand my requirement.
Any help would be appreciated!!!
回答1:
ManufacturerListAdapter will need to return those "mostly frequently selected items" for the first few row positions (e.g., 0, 1, and 2), with the others in whatever order you wish.
Since ManufacturerListAdapter would appear to be a subclass of CursorAdapter, one approach is:
- Do one query to get your "mostly frequently selected items" into one
Cursor - Do another query to get the rest, in the desired order, into another
Cursor - Stitch the two
Cursorobjects together using a MergeCursor - Use the
MergeCursorwith yourManufacturerListAdapter
来源:https://stackoverflow.com/questions/18957097/list-most-frequently-selected-items3-items-at-top-of-the-adapter-using-android