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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:04:39+00:00 2026-05-30T12:04:39+00:00

My application (min level 13) is an Activity that uses tabs in the action

  • 0

My application (min level 13) is an Activity that uses tabs in the action bar to manage a couple fragments, very similar to this.

Now, the activity starts a service which does continuous computation and returns values which I would like to display in the Fragments. The Activity – Service communication is implemented through broadcast receivers and the Activity shuffles the data off to the appropriate Fragment.

Everything seems setup correctly and the data makes it to the Fragment update method but when I try to display the new values in textviews, the new values are never displayed.

The code to change the textviews:

    TextView tv = (TextView) getView().findViewById(R.id.fieldNavGpsTime);
    Double doub = input.getDoubleExtra("com.some.thing.GPS_TIME", -1.0);
    tv.setText(doub.toString());

The code to call the Fragments update methods from the broadcast receiver in the Activity:

    NavigationGuiFragment navfrag = (NavigationGuiFragment) getFragmentManager().findFragmentByTag("navigation");
    if (navfrag != null && navfrag.isResumed())
        navfrag.UpdateNavUI(intent);

I’ve noticed that isVisible() doesn’t seem to ever return true, but I’m not sure what it means or how to change it.

Additionally, I can’t seem to add an imageview to a Fragment programmatically. Here’s the code (which resides in onActivityCreated()):

    this.compass = new BasicCompass(getActivity());
    LinearLayout ll = (LinearLayout) getView().findViewById(R.id.nav_hrztl_lnly);
    ll.addView(this.compass);

The BasicCompass constructor takes a Context, admittedly I’m not completely sure what I’m passing in is correct.

The code for this was more or less taken from a working Activity and dropped into a Fragment to allow for tabs. I’m open to suggestion in regards to changing the structure of the code.

Thanks for any help.

EDIT

The xml layout of the Fragment:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_hrztl_lnly"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:baselineAligned="false" >

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="600dp"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true" >

    <EditText
        android:id="@+id/labelNavGpsTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/gps_time" />

    <EditText
        android:id="@+id/fieldNavGpsTime"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_3_digits"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/labelNavLatitude"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/latitude" />

    <EditText
        android:id="@+id/fieldNavLatitude"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_6_digits"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/labelNavLongitude"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/longitude" />

    <EditText
        android:id="@+id/fieldNavLongitude"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_6_digits"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/labelNavAltitude"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/altitude" />

    <EditText
        android:id="@+id/fieldNavAltitude"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_3_digits"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/labelNavRoll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/roll" />

    <EditText
        android:id="@+id/fieldNavRoll"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_6_digits"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/labelNavPitch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/pitch" />

    <EditText
        android:id="@+id/fieldNavPitch"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_6_digits"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/labelNavAzimuth"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/azimuth_heading" />

    <EditText
        android:id="@+id/fieldNavAzimuth"
        style="@style/field_padding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/zero_6_digits"
        android:inputType="numberDecimal" />

    <LinearLayout
        android:id="@+id/nav_rdbtn_lnly"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/rdbtnNavGpsAvailability"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/gps_avail" />

        <RadioButton
            android:id="@+id/rdbtnNavZuptStatus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/zupt_stat" />

    </LinearLayout>

</LinearLayout>

And the Fragment that uses it:

public class NavigationGuiFragment extends Fragment
{
private RadioButton gpsRdBtn;
private RadioButton zuptRdBtn;
private BasicCompass compass;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    View fragview =  inflater.inflate(R.layout.navigation_fragment, container, false);

    // sets up the rose image that serves as a compass in the GUI
    this.compass = new BasicCompass(getActivity());
    LinearLayout ll = (LinearLayout) fragview.findViewById(R.id.nav_hrztl_lnly);
    ll.addView(this.compass);

    return fragview;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) 
{
    super.onActivityCreated(savedInstanceState);
    getActivity().setContentView(R.layout.navigation_fragment);

    //Initialize the radio buttons
    gpsRdBtn = (RadioButton) getView().findViewById(R.id.rdbtnNavGpsAvailability);
    gpsRdBtn.setChecked(false);

    zuptRdBtn = (RadioButton) getView().findViewById(R.id.rdbtnNavZuptStatus);
    zuptRdBtn.setChecked(false);    
}

@Override
public void onResume() 
{
    super.onResume();

    if (!IsMyServiceRunning())
    {
        gpsRdBtn.setChecked(false);
        zuptRdBtn.setChecked(false);
    }
}

public void UpdateNavUI(Intent input)
{       
    TextView tv = (TextView) getView().findViewById(R.id.fieldNavGpsTime);
    Double doub = input.getDoubleExtra("com.some.thing.GPS_TIME", -1.0);
    tv.setText(doub.toString());

    tv = (TextView) getView().findViewById(R.id.fieldNavLatitude);
    doub = input.getDoubleExtra("com.some.thing.LATITUDE", 100000.0);
    tv.setText(doub.toString());

    tv = (TextView) getView().findViewById(R.id.fieldNavLongitude);
    doub = input.getDoubleExtra("com.some.thing.LONGITUDE", 100000.0);
    tv.setText(doub.toString());

    tv = (TextView) getView().findViewById(R.id.fieldNavAltitude);
    doub = input.getDoubleExtra("com.some.thing.ALTITUDE", -1.0);
    tv.setText(doub.toString());

    tv = (TextView) getView().findViewById(R.id.fieldNavRoll);
    doub = input.getDoubleExtra("com.some.androidndk.ROLL", 361.0);
    tv.setText(doub.toString());

    tv = (TextView) getView().findViewById(R.id.fieldNavPitch);
    doub = input.getDoubleExtra("com.some.thing.PITCH", 361.0);
    tv.setText(doub.toString());

    tv = (TextView) getView().findViewById(R.id.fieldNavAzimuth);
    doub = input.getDoubleExtra("com.some.thing.AZIMUTH", 361.0);
    tv.setText(doub.toString());

    this.compass.SetDirection(doub.floatValue());

    boolean bool = input.getBooleanExtra("com.some.thing.ZUPT_STATUS", false);
    zuptRdBtn.setChecked(bool);

    UpdateGpsIndicator(input);
}

public void UpdateGpsIndicator(Intent input)
{
    boolean bool = input.getBooleanExtra("com.some.thing.GPS_ON", false);
    gpsRdBtn.setChecked(bool);
}

private boolean IsMyServiceRunning()
{
    ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
    {
        if ("com.some.thing.Service".equals(service.service.getClassName())) 
            return true;
    }

    return false;
}

}

  • 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-30T12:04:41+00:00Added an answer on May 30, 2026 at 12:04 pm

    this line:

    getActivity().setContentView(R.layout.navigation_fragment);
    

    should be called in Activity.onCreate() and make sure it is just called once. In your code it will be called every time Fragment moves to active state. And the TextView and RaidoButton stuff will be reset to state define in the layout xml.

    Checkout Fragment lifecycle here.

    UPDATE:
    Some view widget’s state will be kept by Activity, e.g TextView. Try move your setXXX() method to onResume(). I have experience that setXXX() is not working in onActivityCreated() but works well in onResume().

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

Sidebar

Related Questions

I have manage to create a small size js application that uses jQuery and
I use a batch to launch my java application like this start /min java
I am developing an application using jQuery that uses cookies. Right now, it is
so theres this application that is on facebook, so the source is in an
I reference jQuery in my application via: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js . This generates an error with
I'm afraid that I'm not very good at low level C stuff, I'm more
in my application.html, i have this inside: ... <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js></script> ... in my _post.html,
My asp.net mvc application uses files .... http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js Can these be downloaded to
This is probably a pretty high-level question that requires a lot of explaining, but
so im trying to include this file for an application http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js would including it

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.