0

Right now I've Fragments A with Recyclerview - where I've categories (Image+text). I want to make Fragment B with Recyclerview - where I've types (Image+text). Same layout, same everything except text/image. Like this: https://img.exs.lv/e/z/ezeliitis/frags.png

For instance, I click on Fragments A - first picture (Cars) and it opens Fragments B - in same layout as fragment A, which contains (AUDI, BMW, OPEL ect...). Should I just make copies of fragment A (adapters/viewholders ect.) changing db names/pictures or is there some way to "DRY" the code? Also, isn't it bad having two recyclerviews (performance) ?

Also, movement from one fragment to another is called fragments "..."(what exactly?)

JasonM
  • 3
  • 6

1 Answers1

0

Same layout, same everything except text/image

You must need to replace the RecyclerView adapter, then. No need to start another Fragment, but you're more than welcome to.

isn't it bad having two recyclerviews (performance) ?

Not that I know of. You'd only have one at a time, from what I understand anyways.

movement from one fragment to another is called fragments "..."(what exactly?)

If you do need to switch Fragments, then you want the FragmentTransaction class of the host Activity. That's how you switch. Documentation is pretty good with its example.

https://developer.android.com/training/basics/fragments/communicating.html

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1. I'll just make another Fragment, but does that mean I've to make new adapter/holder? 2. How can I make sure, that when I click image one, it will display auto marks, but if I click picture two - it will display foods for example? – JasonM Nov 23 '16 at 00:16
  • If you are displaying different data, then yes, you need a different holder and adapter. Unless you can abstract the data model in some way other way, that's up to your Java model class design... I'm not sure I understand point 2... You would attach different click listeners within the different adapters – OneCricketeer Nov 23 '16 at 00:43
  • 2. For instance, I have 10 categories in fragment A. I decided to click on category 1 (cars) and I transfer to fragment B (containing only car pictures/names, not, for example some food pics/names..). – JasonM Nov 23 '16 at 00:49
  • I don't understand the issue. Yes. You click cars category. It loads a Fragment that loads only cars... Maybe this helps because the other post you made has a wrong answer. http://stackoverflow.com/questions/9245408/best-practice-for-instantiating-a-new-android-fragment – OneCricketeer Nov 23 '16 at 02:14
  • Okay, but if I duplicate fragment B, do I've to make .xml files for item and recyclerview - or I can just have the ones I've and pass diff information as theyre the same? – JasonM Nov 23 '16 at 10:02
  • Again, different data = different / new adapter & layouts *unless you can otherwise abstract your data model*. I can't see the data that you're wanting to show, so I can't tell you what to do for that – OneCricketeer Nov 23 '16 at 10:05
  • Fragment A data - string/image. Fragment B - string/image (different). Exact layout. – JasonM Nov 23 '16 at 10:57
  • The values can be different, but it's the object types that are important and decide whether you need a different adapter – OneCricketeer Nov 23 '16 at 11:52