android - How to add two tables in one RecyclerView with different colour values -
want make above type of recyclerview (in case). in above sample pic, expenses show in red colours zebra lines , income shows in green colours. i've write code expense table values , shown in recyclerview. want show income income table , make view same sample pic. kindly help.
recyclerview expense values:
arraylistexpense = new arraylist<>(); adapterviewitems adapter = new adapterviewitems(mainactivity.this, arraylistexpense); recyclerview = (recyclerview) findviewbyid(r.id.view_item_recycle_view); recyclerview.layoutmanager mlayoutmanager = new linearlayoutmanager(getapplicationcontext()); recyclerview.setlayoutmanager(mlayoutmanager); recyclerview.setadapter(adapter); cursor cursor = db.selectexpense(); cursor.movetofirst(); if (cursor.getcount() == 0) { toast.maketext(this, "empty list", toast.length_short).show(); } else { (int = 0; < cursor.getcount(); i++) { hashmap<string, object> hm = new hashmap<>(); hm.put(id_expense, cursor.getstring(cursor.getcolumnindex(id_expense))); hm.put(name_expense, cursor.getstring(cursor.getcolumnindex(name_expense))); long valueexpense = cursor.getlong(cursor.getcolumnindex(value_expense)); showexpense(valueexpense); hm.put(value_expense, string.valueof(valueexpense)); hm.put(date_expense, utility.dateformat(cursor.getlong(cursor.getcolumnindex(date_expense)))); string id = cursor.getstring(cursor.getcolumnindex(type_id_expense)); hm.put("type", db.selecttypebyid(id)); arraylistexpense.add(hm); cursor.movetonext(); } cursor.close(); }
database:
cursor selectexpense() { cursor cursor = null; try { sqlitedatabase db = this.getwritabledatabase(); cursor = db.rawquery("select " + id_expense + "," + name_expense + "," + value_expense + "," + date_expense + "," + type_id_expense + " " + table_expense + " order " + date_expense + " desc", null); } catch (exception e) { log.d("selectexpenses", " error " + e.getmessage()); } return cursor; }
all need getitemviewtype allow inflate multiple views within recyclerview.
Comments
Post a Comment