1

I have a ViewPager with 3 fragments. One fragment downloads data ​from a website and displays it in TextViews. Now when the user clicks in the menu of the MainActivity on the item "refresh", the fragment should redownloads the data and displays it. I tried to create a function refresh in the fragment's class and call it from the MainActivity's menu. That worked, but then it crashes because the app can't find the textview. The variable view is empty and it causes a null pointer exception.

What can I do to resolve this?

Many thanks!

  • please post more of your logcat, ussualy there is some information about why executing doInBackground() failed. :) – Berťák Mar 27 '13 at 15:30
  • It fails because he can't find the view. In the AsyncTask the Text is set to the TextView, but he can't find the TextView because the view is null. –  Mar 27 '13 at 15:59

1 Answers1

1

From your fragmentactivity,

Fragment tehFraggerz = getSupportFragmentManager().findFragmentByTag(string);

where string is the tag. You set the tag of the fragments in the add, replace, etc methods.

Once you have your fragment, you can do

TextView tehTexterz = (TextView) tehFraggerz.getView().findViewById(R.id.tehText);
SpyZip
  • 5,511
  • 4
  • 32
  • 53
r2DoesInc
  • 3,759
  • 3
  • 29
  • 60
  • Mhm, how can I add a tag to a fragment in my SectionsPagerAdapter? –  Mar 27 '13 at 15:48
  • http://developer.android.com/reference/android/app/FragmentTransaction.html#add(int, android.app.Fragment) – r2DoesInc Mar 29 '13 at 17:52