How To Set Setcontentview?
i creating a project using actionbarsherlock 'menuviewpager' I want to put the class from my project in it. but i got several error. I want to insert imageswitcher into the fragmen
Solution 1:
You should init your ui-objects like this:
@OverridepublicvoidonViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
initUIobjects(view);
}
privatevoidinitUIobjects(View view){
ViewPager viewPager = (ViewPager) view.findViewById(R.id.view_pager);
//... and so on
}
instead onCreate
Solution 2:
http://developer.android.com/reference/android/app/Activity.html#setContentView(android.view.View)
setContentView
is a method of activity class. You can initialize views once the layout is inflated. So ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager)
fails.
I am not sure what you are doing or from where you copy pasted the code.
You probably want activity context
Contextcontext= Fragment1.this;
So use getActivtiy()
Contextcontext= getActivity();
Post a Comment for "How To Set Setcontentview?"