Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

resources - Access to getString() in android.support.v4.app.FragmentPagerAdapter?

In a class extending android.support.v4.app.FragmentPagerAdapter, is there any way to get access to the Context.getString(..) method without the extending class being an inner class of an activity or passing in some context from the outside?

Thanks for any hint!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From a fragment use :

 getActivity().getString(...)

From an adapter use :

 getContext().getResources().getString(...)

Yes, you need a context to access the resources.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...