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 8088511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:06:41+00:00 2026-06-05T19:06:41+00:00

How can I create a PagerView dynamically? Without using a xml? Let’s say that

  • 0

How can I create a PagerView dynamically? Without using a xml? Let’s say that I have a xml layout like this:

<FrameLayout android:id="@+id/a_frame_for_pagerview"
             ... >

<!-- I WANT MY PAGERVIEW HERE BUT DYNAMICALLY, NO XML -->

</FrameLayout>

It don’t need to be a FrameLayout, just used it because I thought it would be the case.

Thanks for your help.

EDIT:

My main problem is that I have too many pagers that crash because of memory and I want them to be disposed but even I removing the Fragment where the pager is inside, it keeps reference to the older pager(from the first time I create the fragment) where all the fragments are destroyed, so nothing appears.

  • 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-05T19:06:42+00:00Added an answer on June 5, 2026 at 7:06 pm

    You can do it with :

    In your XML :

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    

    In your frament :

    [....]
    mViewPager.setAdapter(new MyFragmentAdapter(getFragmentManager()));
    [....]
    public class MyFragmentAdapter extends FragmentPagerAdapter{
    
        public MyFragmentAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }
    
        @Override
        public Fragment getItem(int arg0) {
            // TODO Auto-generated method stub
            YourClassFragment fragment = new YourClassFragment();  
            Bundle args = new Bundle();  
    
            args.putParcelable("EXTRA_DATA", "VALUE");  
            fragment.setArguments(args);  
    
            return fragment;  
        }
    
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return yourNumberOfFragment;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have application like where i can create dynamic tabs. and delete cross bar
This can create an array dynamically: Assembly asm = object.GetType().Assembly; string sTypeName = Company.Namespace.ClassName;
how can create ratings using UIPicker, eg. 0-star to 5-star, how this can be
I can create a new object like this: Dim sqlconn As New SqlClient.SqlConnection(cs) or
I can create a confirm box in Ext JS like this: with this code:
I can create an Global Atom using GlobalAddAtom and I can find that atom
Let's say that I have an article on a website, and I want to
I can create an array and initialize it like this: int a[] = {10,
I can create a jquery object inline like this (this code is working) $('#tip').qtip({
You can create a new List in Scala using: 1 :: 2 :: Nil

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.