0

I have an ActionBar and it has Tabs. In the MainActivity there is a LocationListener implemented.

In onLocationChanged(Location location) method I save the longitude value to double longitude variable.

I would like to pass this value to the RunFragment class.

Could anybody help me?

This is the MainActivity code:

public class MainActivity extends FragmentActivity implements ActionBar.TabListener, LocationListener{

ActionBar actionbar;
ViewPager viewpager;
FragmentPageAdapter ft;

double longitude;

private LocationManager lm;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    viewpager = (ViewPager) findViewById(R.id.pager);
    ft = new FragmentPageAdapter(getSupportFragmentManager());

    actionbar = getActionBar();
    viewpager.setAdapter(ft);
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionbar.addTab(actionbar.newTab().setText("Run").setTabListener(this));
    actionbar.addTab(actionbar.newTab().setText("Map").setTabListener(this));
    actionbar.addTab(actionbar.newTab().setText("Statistics").setTabListener(this));
    viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {            

    });


protected void startLocationUpdate() {
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}


public void onLocationChanged(Location location) {
    longitude=location.getLongitude();

}

This is the RunFragment code:

public class RunFragment extends Fragment {

TextView tv;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.run_layout, container, false);
    tv =(TextView)view.findViewById(R.id.textView1);

    return view;

}


public void setTv(String string){
    tv.setText(string);
}

}

kalmi
  • 13
  • 6

1 Answers1

0

Can't you get a reference to the RunFragment on the Activity through a findViewById()? Then add a method to RunFragment and call it from onLocationChanged().

jcmanke
  • 56
  • 1
  • 4