Help, people, well, I do not understand this topic at all. I take the data from the local database and use the cursor to scatter it in two ArrayList. (intValue is the value for the filter)

final Cursor cursor = mSqLiteDatabase.query("products", new String[] {DatabaseProductHelper.PRODUCT_NAME, DatabaseProductHelper.PRODUCT_COUNT, DatabaseProductHelper.PRODUCT_LIST, DatabaseProductHelper.PRODUCT_TYPE}, null, null, null, null, null) ; final ArrayList<String> arrTblNames = new ArrayList<String>(); final ArrayList<String> arrTblCounts = new ArrayList<String>(); 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"))); } cursor.moveToNext(); } 

Everything. Data in two ArrayList-ah. My task is to output data from the first to the left TextView, and from the second to the middle. I prepared the appropriate markup and I did it!

 san = arrTblNames.toArray(new String[0]); myArrList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map; for(int a = 0; a<san.length; a++) { map = new HashMap<String, String>(); map.put("name", arrTblNames.get(a)); map.put("count", arrTblCounts.get(a)); myArrList.add(map); } SimpleAdapter adapter = new SimpleAdapter(this, myArrList, R.layout.row, new String[] { "name", "count" }, new int[] { R.id.name_product, R.id.count_product}); lv_products.setAdapter(adapter); 

Everything is fine, but ... HOW TO ADD A CheckBox? The checkbox should also work with the database.

    1 answer 1

    you need not to create two separate ArrayList for each markup, but to create an object that you will initialize with data from the database, and transfer ArrayList<CustomObject> to your adapter. The object will look like this.

     public class CustomObject { public String name; public int count; public boolean isChecked; } 

    And you can fill in the created array of objects

      final ArrayList<CustomObject> items = new ArrayList<CustomObject>(); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { if (cursor.getInt(cursor.getColumnIndex("list")) == intValue) { CustomObject customObject = new CustomObject(); customObject.count = cursor.getString(cursor.getColumnIndex("count")) + " " + cursor.getString(cursor.getColumnIndex("type")); customObject.name = cursor.getString(cursor.getColumnIndex("name")); items.add(customObject); } cursor.moveToNext(); } } 

    Accordingly, you can now add any fields to your CustomObject and display them in your foliage.