Android: is using setContentView multiple times bad while changing layouts?

后端 未结 3 1087
青春惊慌失措
青春惊慌失措 2020-11-28 15:34

is using setContentView multiple times bad while changing layouts?

Some people say that it\'s bad and they never say why.

and is there some other thing to ch

3条回答
  •  执念已碎
    2020-11-28 15:58

    i cant show example because i'm waiting for answer to do it. okay i have the app of lyrics(it will show lyrics of band) and albums are new activities but i dont want many activities and thats why i want to make songs only layouts and change views with button press

    It sounds like you're going about this the wrong way. If you want to change the UI an Activity contains, then Fragments would be the better approach. There's a bit of a learning curve there, but it's good android design, and well documented.

    Further, you seem to be confusing formatting and content. If you're displaying song lyrics, you don't need a new layout for each song. You just need to change the lyrics and keep them in the same activity. What you're doing is akin to creating a new web-browser for each web-page you intend to visit. Instead, find a way to store the lyrics and display them on a single activity (or in a fragment) to display those lyrics. The same would apply to each album: One activity would display the album cover in the corner (or as background), the title, release date, etc, as text, and then a list of songs below. The actual content of the TextViews can change, but the layout ought to be the same.

提交回复
热议问题