2013-04-20 13 views
6

Nie można użyć kontekstu w FragmentPagerAdapter. RadioGroup(this) daje mi niezdefiniowany błąd. Kiedyś getContext() Zamiast tego, ale nie mógł go osiągnąćUżywanie kontekstu w narzędziu FragmentPagerAdapter

private static class MyFragmentPagerAdapter extends FragmentPagerAdapter { 

final RadioGroup rg = new RadioGroup(this); // what can I use instead of "this" ? 

} 

Odpowiedz

16

Nie jestem pewien, dlaczego jesteś uruchamianiu tego radiogroup w FragmentPagerAdapter, ale mimo to można uzyskać przez modyfikację kontekstu konstruktora klasy:

private Context context; 

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

Następnie można dodać kontekst podczas tworzenia FragmentPagerAdapter.

Powiązane problemy