Using context in a FragmentPagerAdapter

I could not use the context in the FragmentPagerAdapter . RadioGroup(this) gives me an undefined error. Instead, I used getContext() , but could not reach it.

 private static class MyFragmentPagerAdapter extends FragmentPagerAdapter { final RadioGroup rg = new RadioGroup(this); // what can I use instead of "this" ? } 
+6
source share
1 answer

I'm not sure why you are creating a RadioGroup in the FragmentPagerAdapter, but you can get the context anyway by changing the class constructor:

 private Context context; /** Constructor of the class */ public MyFragmentPagerAdapter(FragmentManager fm, Context c) { super(fm); context = c; } 

You can then add context when creating the FragmentPagerAdapter.

+16
source

All Articles