Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:53+00:00 2026-05-28T22:08:53+00:00

Until now I’ve used TabHost for my App to create 3 Tabs. Each Tab

  • 0

Until now I’ve used TabHost for my App to create 3 Tabs. Each Tab is represented by an Activity in which I get the layout via setContentView(R.layout.something) from an XML file.
So 3 Tabs, 3 Activities and 3 XML files.

Now I’ve stumbled upon fragments, which are the new and better way to go, so here is my question.

Fragments handle the UI, so create 3 Fragments which are handled by FragmentPagerAdapter. Inside each Fragment I create the Content via XML files.

But where do I put all the code about which button does what, read from database or write to it etc. So far that’s all been in each Activity that was loaded by the Tabhost.

Do I put all that code into the onCreate() etc. methods of each fragment or is there a better and cleaner way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:08:53+00:00Added an answer on May 28, 2026 at 10:08 pm

    The approach you propose is pretty much fine!

    In terms of what to do where, I’d recommend that you do anything to create/alter the the UI of a page (fragment) in onCreateView() of each fragment, and any logic (reading databases etc) in onActivityCreated(). I’d recommend steering clear of onCreate() in a fragment, because this is called before it is associated with an Activity (preventing you doing thigs such as managed queries to contentproviders). Button click listeners could be defined either in onCreateView or onActivityCreated().

    Anything more specific, let me know. Dont forget, standard Pagers don’t include a row of tab titles/icons, but Google ViewPagerIndicator and you’ll find a library which you can use to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Until now i have used Graphviz to programmatically create diagrams and graphs. Recently, I
Until now I've always used the ASP.NET MVC framework source for debugging ASP.NET MVC.
Until now I've been used to using DAOs to retrieve information from databases. Other
Up until now we used Ant in my company. Whenever we wanted to send
Up until now I used DateTime.Now for getting timestamps, but I noticed that if
Until now, I believed that -(void)startToDoSomethingWithThis:(That*)thing andThat:(That*)otherThing has the following method signature, which is
Until now, I've used jQuery validation plugin with previously defined fields. Now I'm working
From what I have read until now, you can get the TargetPath property of
in my project I have until now synchronized multiple threads (each running the same
Up until now I've only used DLL's as a source for plugins in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.