getString(int resId)
it gives a error message "Cannot make a static reference to the non-static method getString(int) from the type Context".public CharSequence getPageTitle(int position)
I need to get like this name = getString(R.string.mystring)
any help is appreciated.public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { public AppSectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { switch (i) { case 0: Fragment fragment = new Activity1(); return fragment; case 1: Fragment fragment1 = new Activity2(); return fragment1; default: return new Activity2(); } } @Override public int getCount() { return 2; } public CharSequence getPageTitle(int position) { String name = null; if (position==0) { name = "Movie Details"; }else if (position==1) { name = "Movie Comments"; } return name; } }
You need a Context
object to call getResources().getString(int resID)
. Try passing a Context
in your constructor and using it here like
Context mContext;
public AppSectionsPagerAdapter(FragmentManager fm,Context context) {
super(fm);
mContext = context
}
and then use mContext.getResources().getString(int resID)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With