List most frequently selected items(3 items) at top of the adapter using android list fragments?

旧街凉风 提交于 2019-12-11 19:26:57

问题


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 Cursor objects together using a MergeCursor
  • Use the MergeCursor with your ManufacturerListAdapter


来源:https://stackoverflow.com/questions/18957097/list-most-frequently-selected-items3-items-at-top-of-the-adapter-using-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!