I trying to set the title for my viewpager, I can\'t seem to get it to work. I tried Resources.getSystem().getString(R.string.title1); and also tried to pass a context. Coul
You are trying to fetch String
inside your Resources
without gaining Resources
. So try to pull your Resources
with getResources()
with your Context
.
If your are inside Activity
or Service
then context is there. If outside then try to pull Context
first with getApplicationContext()
and on that pull the resources and pull your String
in the end on it.
As per your Code these snippet would't throw any exception if resources
and mentioned String
id's are pulled properly.
public CharSequence getPageTitle(int position)
{
switch (position)
{
case 0:
return getResources().getString(R.string.title1);
case 1:
return getResources().getString(R.string.title1);
case 2:
return getResources().getString(R.string.title1);
}
return null;
}