I want to make above type of RecyclerView (in my case). In above sample pic, the expenses show in red colours with zebra lines and income shows in green colours. I've write code for expense table values and successfully shown in RecyclerView. Now I want to show income from income table and make view same as sample pic. kindly help.
RecyclerView with 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 {
for (int i = 0; i < 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 + " FROM " + TABLE_EXPENSE
+ " ORDER BY " + DATE_EXPENSE + " DESC", null);
} catch (Exception e) {
Log.d("selectExpenses", " error " + e.getMessage());
}
return cursor;
}