java - Android RecyclerView pass and display Item data depending on condition -
i have recyclerviewactivity , data recyclerview:
// reference recyclerview recyclerview recyclerview = (recyclerview) findviewbyid(r.id.recyclerview); // data recyclerview carddata carddata[] = { new carddata("bread", r.drawable.bread), new carddata("dairy", r.drawable.dairy), new carddata("meat", r.drawable.meat) ...}
each carddata connected different activity simple listview.
now used shared preferences , boolean variable check if there items in every listview. after check completes - pass true/ false value recyclerviewactivity:
sharedpreferences pref = getsharedpreferences("filename", mode_private); boolean = pref.getboolean("key1", false); boolean b = pref.getboolean("key2", false); boolean c = pref.getboolean("key3", false);
now need - to display carddata depending on a/b/c values. if receive a: true - need display additional image indicator in data set. this:
carddata carddata[] = { if (!a) { new carddata("bread", r.drawable.bread, r.drawable.indicator) } else { new carddata("bread", r.drawable.bread) }; if (!b) { new carddata("dairy", r.drawable.dairy, r.drawable.indicator) } else { new carddata("dairy", r.drawable.dairy}; ... }
the problem don't , how can set condition. inside carddata above does'n work - gives me syntax error..
any appreciate!
the problem aren't breaking smaller, more manageable steps.
you can in way:
// initialise array size 3 carddata carddata[] = new carddata[3]; // start adding elements // insert first object checking flag "a" if (a) { carddata[0] = new carddata("bread", r.drawable.bread); } else { carddata[0] = new carddata("bread", r.drawable.bread, r.drawable.indicator); } // insert second object checking flag "b" if (b) { carddata[1] = new carddata("dairy", r.drawable.dairy); } else { carddata[1] = new carddata("dairy", r.drawable.dairy, r.drawable.indicator); } // , on...
Comments
Post a Comment