1

So I got three ViewPagers.

  1. MainPager this one contains all views and both ScoreboardPager and StopwatchPager
  2. ScoreboardPager this contains a few TextViews which act like timers
  3. StopwatchPager this contains a few TextViews which keep track of score

The issue with this is that I'm unable to get any of the TextViews from either 2 or 3.

I call findViewFromId inside StopwatchFragment and ScoreboardFragment, like this:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main_stopwatch, container, false);
    MainFragment.StopwatchTimeBlue = (TextView) rootView.findViewById(R.id.stopwatchTimeBlue);        
    MainFragment.StopwatchTimeOrange = (TextView) rootView.findViewById(R.id.stopwatchTimeOrange);
    return rootView;
}

When I try and assign a value to it, it won't get updated. I assign it like this, inside MainFragment.

if (blueScore > 0) {
    if (StopwatchTimeBlue != null) {
        Log.i("Timer", String.format("Found stopwatchTimeBlue, value is ", StopwatchTimeBlue.getText().toString()));
        StopwatchTimeBlue.setText(timeInText);
    }
}

Any help is welcome

Blapple
  • 67
  • 1
  • 1
  • 11
  • Why is your code incomplete? ` MainFragment.StopwatchTimeBlue = (TextView) rootView.findViewById(R.id.stopwatchTimeBlue); MainFragment.StopwatchTimeOrange = (TextView) rootView.findViewById(R.id. ` – Jas Mar 09 '16 at 12:51
  • Woops, I didn't even notice. I fixed it now – Blapple Mar 09 '16 at 12:53
  • Why are you using `MainFragment.StopwatchTimeOrange ` ? Why can't you use `StopwatchTimeOrange ` alone? – Jas Mar 09 '16 at 12:56
  • I need to use StopwatchTimeOrange in MainFragment – Blapple Mar 09 '16 at 12:57
  • Use Interface for Each View pager see this example http://stackoverflow.com/a/20412875/4146722 – Pratik Tank Mar 09 '16 at 13:01
  • @PräTîkTank I'm not sure why I would need to use that, my fragments update fine. – Blapple Mar 09 '16 at 13:03

0 Answers0