Ahsan S. Sher
Ahsan S. Sher

Reputation: 108

android - add/remove views dynamically: Activities vs Fragments

I want to ask which is best approach to add e.g or using to the screen? Should I use the method described here Android - Dynamically Add Views into View (i think its for Activity) or should I use fragment in app.

I'm making an simple CGPA calculator app. I want to add another in for another subject/course if user presses "Button" marked with "+". I hope you got the idea.

I just want to know which is best way to do it. I'm very beginner , ignore if you find this question stupid.

Upvotes: 0

Views: 184

Answers (1)

Rod_Algonquin
Rod_Algonquin

Reputation: 26198

I want to add another in for another subject/course if user presses "Button" marked with "+".

Fragments will be in favor here based on your question. So when each time you click the button you just add next fragment to the activity layout, make sure that you dont use the replace method of the fragment manager that it will replace the layout of the activity_main use the add method instead. You can follow this thread on how to add fragment to the activity.

Upvotes: 1

Related Questions