I have my own adapter for ListView inherited from SimpleCursorAdapter . In each item, I have 2 TextView and CheckBox . Checkbox states are loaded from the database. It is necessary to implement the following: first, in the list only items with the unchecked checkboxes are displayed (in the 'complete' column in the database it is 0 ). And after them - items with checked checkboxes (in the column is 1 ).
What I've done
At first I showed laziness and decided to make two lists. Everything is fine, only there were problems with the scrolling. And in general, it is a crutch. Somehow not good at it.
I decided to filter the
booleanarray with checkbox states (firstfalse, thentrue). Happened. But between checkboxes and text in the item, and in general there was no correspondence with the record id. Since I changed the order of checkboxes, and did not touch the rest.I decided to rewrite the adapter altogether, the idea went well, but after compiling and running the application crashed with a billion errors that I could not figure out. After all these rakes, I could not stand it and decided to ask you, the people.
Adapter code
I don’t remember how I did everything, so I returned the code to its original position. Where the list is displayed as is .
public class ListCursorAdapter extends SimpleCursorAdapter { private int layout; public ListCursorAdapter(Context _context, int _layout, Cursor _cursor, String[] _from, int[] _to) { super(_context, _layout, _cursor, _from, _to); layout = _layout; } @Override public void bindView(View view, Context _context, Cursor _cursor) { String list_name = _cursor.getString(_cursor.getColumnIndex(DatabaseHelper.LIST_NAME)); String list_data = _cursor.getString(_cursor.getColumnIndex(DatabaseHelper.LIST_TIME)); int chb_list = _cursor.getInt(_cursor.getColumnIndex(DatabaseHelper.LIST_COMPLETE)); TextView name_list_tv = (TextView)view.findViewById(R.id.lv_list_name); TextView data_list_tv = (TextView)view.findViewById(R.id.lv_list_data); CheckBox chb_lists = (CheckBox) view.findViewById(R.id.chb_list_complete); chb_lists.setClickable(false); chb_lists.setFocusable(false); name_list_tv.setText(list_name); data_list_tv.setText(list_data); chb_lists.setChecked(chb_list==1); } @Override public View newView(Context _context, Cursor _cursor, ViewGroup _parent) { LayoutInflater inflater = (LayoutInflater)_context.getSystemService(_context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(layout, _parent, false); return view; } } What I need:
In ListView now the data from the database are displayed as is, in order. I need to change this order: first go items with data from the base rows with zeros in the 'complete' column. Then in the list should be displayed items with data from the rows of the database with units. In other words, first I need to show items with state checkboxes false , and then with true . And not like now - the data from the database is simply taken and in turn placed in the item. You need to turn down
How to solve this problem?
querymethod, through which a query is made to the database, there is an orderBy parameter (the seventh parameter), which sorts the cursor according to your wishes / And you need to be as I told you - to read books and not to invent unreal crutches, to which waste time. - pavlofff