androidandroid-layoutandroid-fragmentsfragmentgoogle-now

Add a single fragment to a screen multiple times


I am new to android and I am working on a project that displays cards (like on Google Now but all cards are the same size). My question is, is it possible to add the same fragment (a general design for the card) multiple times to the same screen and have them be position after each other in a row or column? If so how would I go about that?


Solution

  • Yes you can. Create a template fragment (eg. TempFragment extends Fragment). Then initilise a new TempFragment each time you need with the data you want to display and use a FragmentManager to add it to the view you want. As for the row or column layout you can use TableLayout in your main layout. Your question is very vague and I'm afraid I can only help you this far.