There is a local database with a column "complete" in which data of the type boolean is stored (I send true | false - 1 | 0 is written, respectively). There is also a ListView built on SimpleAdapter There is a CheckBox on each list item. That's what they need to programmatically set the value true | false true | false taken from db. But I can’t manage to finish my plans, I stopped at the last part. Instead of setting the checkbox for values 1 and 0 set / not set, to the right of it, this value is simply displayed (either 0 or 1 ). Since I did the following from http://developer.alexanderklimov.ru/android/theory/simpleadapter.php#customlayout2 , I guess what the problem is and I understand that it is easily resolvable) The example uses a ready-made array of Boolean - values I fill ArrayList . And here is my code
final Cursor cursor = mSqLiteDatabase.query("products", new String[] {DatabaseProductHelper.PRODUCT_NAME, DatabaseProductHelper.PRODUCT_COUNT, DatabaseProductHelper.PRODUCT_LIST, DatabaseProductHelper.PRODUCT_TYPE, DatabaseProductHelper.PRODUCT_COMPLETE}, null, null, null, null, null) ; final ArrayList<String> arrTblNames = new ArrayList<String>(); final ArrayList<String> arrTblCounts = new ArrayList<String>(); final ArrayList<Integer> arrTblComplete = new ArrayList<Integer>(); if (cursor.moveToFirst()) { while (!cursor.isAfterLast() ) { if (cursor.getInt(cursor.getColumnIndex("list"))==intValue) { arrTblNames.add(cursor.getString(cursor.getColumnIndex("name"))); arrTblCounts.add(cursor.getString(cursor.getColumnIndex("count")) + " " + cursor.getString(cursor.getColumnIndex("type"))); arrTblComplete.add(cursor.getInt(cursor.getColumnIndex("complete"))); } cursor.moveToNext(); } san = arrTblNames.toArray(new String[0]); myArrList = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map; for (int a = 0; a < san.length; a++) { map = new HashMap<String, Object>(); map.put("MemberID", arrTblNames.get(a)); map.put("Name", arrTblCounts.get(a)); map.put("checked_product", arrTblComplete.get(a)); myArrList.add(map); } SimpleAdapter adapter = new SimpleAdapter(this, myArrList, R.layout.row, new String[] { "MemberID", "Name", "checked_product" }, new int[] { R.id.ColMemberID, R.id.ColName, R.id.chb_products}); lv_products.setAdapter(adapter); } When I try to change the ArrayList type to Boolean it swears at the code for taking data through the cursor. So how to be? In the database, the data is stored as numbers ( 0 or 1 ). Can I take them in ArrayList for int type, and then use the filter to remake it in ArrayList for boolean ?
(arrTblComplete.get(a).equals("0"))?false:true)? or(arrTblComplete.get(a)==0)?false:true)- Juriy Spb ♦RecyclerViewright away. - Yuriy SPb ♦RecyclerVieweverything is the same, only you will need to implement all this functionality yourself, since there is nothing ready for this widget, but many people love it :). - pavlofff