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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:30:34+00:00 2026-06-06T11:30:34+00:00

Really simple but just not getting it. I want to reference a view by

  • 0

Really simple but just not getting it.
I want to reference a view by ID that is in the Fragments XML File that I inflate.

I’m declaring the view.

TextView nameView;

I’m getting the view from the layout.

View view = inflater.inflate(R.layout.trackfrag, group, false);
nameView = (TextView)view.findViewById(R.id.trackName);

I get the problem in the below method when it is called from its activity.

 public void setTrackDetails (String name, String description) {
    Log.e("TRACKFRAG", "setTrackDetails Called");
    nameView.setText(name);
    Log.e("TRACKFRAG", "setTrackDetails Finished");
}

Any help would be much appreciated.

ADDED XML

            <TextView
            android:id="@+id/trackName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/anchor"
            android:text="Track Name"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="22sp" />

The Fragment loads up and is displayed fine if I don’t call this method but I need a way of changing the text in one of the Text Views.

ADDED FRAGMENT CREATION

public void onTrackSelected(String track) {
    Log.e("FRAGTRANS","History List Pressed");

    Fragment trackFrag = getFragmentManager().findFragmentByTag("historytrack");
    if (trackFrag == null) {
        trackFrag = new TrackFragment();
        Log.e("TRACKSEL","new trackfrag created");
    }

    addFragment(trackFrag, true, HISTORYTAG, FragmentTransaction.TRANSIT_NONE);

    ((TrackFragment) trackFrag).setTrackDetails(track,"testing");
}

ADD FRAGMENT METHOD

void addFragment(Fragment fragment, boolean addToBackStack, String tag, int transition) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(android.R.id.content, fragment);
        ft.setTransition(transition);
        if (addToBackStack)
            ft.addToBackStack(null);
        ft.commit();
    }
  • 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-06T11:30:35+00:00Added an answer on June 6, 2026 at 11:30 am

    Your problem is in invoking setTrackDetails() method. Please look here where you can see that:

    Calling commit() does not perform the transaction immediately. Rather, it schedules it to run on the activity’s UI thread (the “main” thread) as soon as the thread is able to do so.

    So just after you invoke commit your fragment is not created yet or creating is in progress and your nameView isn’t set yet.
    Best solution would be after creating your fragment(can be after setting nameView because fragment already has activity) invoking method from activity which takes text:

    View view = inflater.inflate(R.layout.trackfrag, group, false);
    nameView = (TextView)view.findViewById(R.id.trackName);
    String str = ((MyActivity)getActivity()).getTextForLabel();
    nameView.setText(str);
    

    Please read documentation about fragments and its lifecycle.

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

Sidebar

Related Questions

I feel like this might be really simple but I'm just not getting it
This must be really simple but just not getting my syntax right here. let's
I am sure this is really a simple solution that I am just not
This is probably something really simple but for some reason I just can't seem
I just cannot figure this out, it looks really simple but I'm relatively new
There might be a really simple solution to this question, but i just don't
May be its a simple question but it's really driving me crazy. I just
I have a really standard splash screen, just a simple Default.png, but for whatever
That may be really simple but I'm unable to find a good answer. How
I know this probably really simple but Im not sure what im doing wrong...

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.