I am trying to use a ViewPager inside a custom Dialog… is it possible to use ? Am using the v4 support library “android.support.v4.view.ViewPager” inside the custom dialog xml.
When I run the application the ViewPager object throws a nullpointerexception..
please help
My custom dialog xml file is as follows :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="300dp"
android:minHeight="400dp"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/myfivepanelpager"
android:tag="test"/>
</LinearLayout>
And I have added 5 pages in viewpager which I have added using PagerAdapter…
The below code is present in the main activity onCreate() method :
Dialog d = new Dialog(this);
Window window = d.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d.setTitle("Dialog");
d.setContentView(R.layout.dialog);
final MyPagerAdapter adapter = new MyPagerAdapter();
final ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(2);
here my pager is returning null… and when i run the code it shows nullpointerexception
If you are having your ViewPager in
R.layout.dialog, then you have to provide the reference of your view object when you Initialize it. Change your code like this,Add the Object of Dialog “d” as I have done here and check.