0

I would just like to know the pros and cons of adding buttons to the activity_main.xml and fragment_main.xml for android app development. I tried looking this up but couldn't find anything useful. I know that you can add buttons to both files but which one is the correct file to add a button to? Can anyone give me an insight on this?

Redson
  • 2,098
  • 4
  • 25
  • 50

1 Answers1

0

Either one is fine, though generally you would do most of your UI work in fragments. There are lots of differences between a Fragment and an Activity, but the general idea is that fragments allow you to reuse portions of your UI multiple places in the app. This is especially important when working with multiple format factors (e.g.: phone vs. tablet) to create layouts that work for both.

Stackoverflow has a lot of good posts on this exact topic; see Android - I need some clarifications of fragments vs activities and views

Community
  • 1
  • 1
Eric Farraro
  • 865
  • 2
  • 7
  • 14