Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8152701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:47:27+00:00 2026-06-06T15:47:27+00:00

I am trying to use a ViewPager inside a custom Dialog… is it possible

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:47:28+00:00Added an answer on June 6, 2026 at 3:47 pm

    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,

    final ViewPager myPager = (ViewPager)d. findViewById(R.id.myfivepanelpager); 
    

    Add the Object of Dialog “d” as I have done here and check.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use viewpager in my app. I want to create 4 view
I was trying use svn to find a checkin using svn log, but it
I was trying use a set of filter functions to run the appropriate routine,
I'm a little confused here, I am trying use a partial view in a
I'm trying to make use of the extended HTML Helper DisplayFor in this View:
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()
I am trying use the onClick() function in an activity for an android app.
I am relatively new to CMake, and I'm trying use the boost asio library
i am trying to use a Html.RenderPartial but getting an error: 'Using' must end
I'm trying to use FragmentActivity with ViewPager to display dynamic list of Fragments .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.