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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:38:12+00:00 2026-05-31T20:38:12+00:00

I am inflating Views (not fragments) in my viewpager implementation. My main class extends

  • 0

I am inflating Views (not fragments) in my viewpager implementation.
My main class extends Activity.

Page 1 of the viewpager inflates a view made up of textviews. Page 2 inflates an achartengine piechart. All works well.

Page 3 is supposed to inflate a listview with a custom adapter. However, as I’ve only extended Activity, setListAdapter isn’t available.

If I change the main class to extend ListActivity, then the entire activity fails on load because it can’t find the android.R.id.list view (because it hasn’t been inflated yet)

This is the instantiate code I am using

public class SummaryPagerAdapteri extends PagerAdapter{

    @Override
    public int getCount() {
        return 5;
    }

    @Override
    public Object instantiateItem(View collection, int position) {

        LayoutInflater inflater = (LayoutInflater) collection.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        int resId = 0;
        View view = null;
        switch (position) {
        case 0:
            //find and inflate the view
            resId = R.layout.recordsummary_one;
            view = inflater.inflate(resId, null);

    //do stuff
            break;
        case 1:
    //find and inflate the view
            resId = R.layout.recordsummary_two;
            view = inflater.inflate(resId, null);
            Context ctx = view.getContext();
            //do stuff  
            break;
        case 2:
            resId = R.layout.recordsummary_three;
            view = inflater.inflate(resId, null);
            Context tctx = view.getContext();
            if(pdn != null){
            adapter = new SummaryNotesAdapter(tctx,pdn);
            setListAdapter(adapter);
            }                  
            break;
        case 3:
            resId = R.layout.recordsummary_four;
            view = inflater.inflate(resId, null);
    //ToDo
            break;
        case 4:
            resId = R.layout.recordsummary_five;
            view = inflater.inflate(resId, null);
    //ToDo
            break;
        }

        ((ViewPager) collection).addView(view, 0);

        return view;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);

    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == ((View) arg1);

    }

    @Override
    public Parcelable saveState() {
        return null;
    }
}

Any ideas on how I can use setListAdapter(adapter) without extending ListView, or how I can extend ListView without the activity failing when it can’t find the uninflated view on first load?

Many thanks

Dave

  • 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-05-31T20:38:14+00:00Added an answer on May 31, 2026 at 8:38 pm

    Inflate a regular ListView for page 3 and call ListView.setAdapter() to set the adapter. In your code this will either be:

    ListView listView = (ListView) inflater.inflate(resId, null);
    listView.setAdapter(adapter);
    

    or

    view = inflater.inflate(resId, null);
    ListView listView = (ListView) view.findViewById(R.id.id_of_your_listview);
    listView.setAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Guys i got the android.view.InflateException: Binary XML file line #1: Error inflating class
I am inflating a view and putting the view below another, everything is fine
I am new to android development and keep coming across references to Inflating views
Which method is better? 1) Using a listview 2) Inflating and adding views in
I have been playing with the list activity tutorial here: http://developer.android.com/resources/tutorials/views/hello-listview.html which tells you
Hi I'm working with a view pager and fragments. I would like to override
While researching how to create custom compound views in Android, I have come across
How can i draw a view on a canvas by giving the x,y position
I have been working on this Tab View and I finally got it working
On an Android Activity, I want to set an image as the background in

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.