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 8891207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:40:53+00:00 2026-06-14T22:40:53+00:00

I have a FragmentActivity which sets a main layout with 3 tabs. Each tab

  • 0

I have a FragmentActivity which sets a main layout with 3 tabs. Each tab has it’s own fragment which inflates is own layout into main layout.

For example, one of the three Fragments:

public class Fragment1 extends Fragment {

  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    if (container == null) {
            return null;
        }
    return inflater.inflate(R.layout.fragment1, container, false);
  }
}

When I add all the fragments and connect them with tabs everything works. When I click on tab1, layout of the Fragment1 shows, when I click on Tab2, layout of the Fragment2 shows.

The problem is that when I want to change something in that inflated layout (for example execute setText to textView in fragment1 layout), I receive a NullPointerException in that line and application stops.

This doesn’t work:

 TextView test = (TextView) findViewById(R.id.fragmentOneText1);
 test.setText("Test text!");

How to set data to inflated layout?

  • 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-06-14T22:40:55+00:00Added an answer on June 14, 2026 at 10:40 pm

    You have to inflate your fragment specific layout first by using LayoutInflater and map the control in your Fragment

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
            View fragmentView = inflater.inflate(R.layout.R.layout.fragment1, container, false);
            TextView text = (TextView) fragmentView.findViewById(R.id.fragmentOneText1);
            mTextNoResult=(TextView)fragmentView.findViewById(R.id.text_noresult);
            return fragmentView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a FragmentActivity that sets up a tabhost. Each tab is a simple
I have Mainactivity which extend FragmentActivity ,I am loading fragment in layout using LinearLayout
I have have a FragmentActivity with two tabs which are ListFragment s. Each ListFragment
I have class that extend FragmentActivity in it I add fragment to layout as
I have a FragmentActivity with a FragmentPagerAdapter which holds a number of Fragment objects
I have a FragmentActivity this activity has a Fragment this Fragment consist from widgets
I have an application which has a TabHost set up with 5 tabs. These
I have fragments in a FragmentActivity, that has an ActionBar and Tab navigation. My
In my Android application, I have a fragment activity which it has a progressbar.
I have a tabhost with 5 tabs which are FragmentActivity . One of them

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.