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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:07:50+00:00 2026-05-25T10:07:50+00:00

So far I’ve been hacking together examples to get a feel for the APIs

  • 0

So far I’ve been hacking together examples to get a feel for the APIs the Android SDK as a whole. However, I’ve hit an impasse.

I’m trying to Inflate a LinearLayout with 2 TextViews from an XML file. These will be then Views that are paged. I simply can’t get this to work and realize that I totally don’t understand what’s going on with the code.

Looking at the source I can see that the method ViewPager.addNewItem calls the InstantiateItem from the supplied adapter. And addNewItem is called in populate(). populate() is called in a number of other places.

Anyway, in the example, I’ve experienced that when the method is overridden for PagerAdapter one must include a call to addView() on the ViewPager collection that is passed from the ViewPager as an argument.

If I wish to add multiple views I thought this would be a case of calling addView() more than once but as instantiateItem() returns an Object to ViewPager (in the example I had it returns the view that it added) I don’t know what to return. I’ve tried returning the inflated view and a number of other things.

Please, can someone explain what is happening here?

Much appreciated.

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

    layout = inflater.inflate(R.layout.animallayout, null);
    TextView tv = (TextView) layout.findViewById(R.id.textView1);
    tv.setText("1________________>" + position);

    TextView tv2 = (TextView) layout.findViewById(R.id.textView2);
    tv.setText("2________________>" + position);

    ((ViewPager) collection).addView(layout);
    return layout;
}
  • 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-25T10:07:50+00:00Added an answer on May 25, 2026 at 10:07 am

    I’ve recently implemented this and this is my instantiateItem method (made it a bit minimal for readability.

    @Override
    public Object instantiateItem(View collection, int position) {
        Evaluation evaluation = evaluations.get(position);
    
        View layout = inflater.inflate(R.layout.layout_evaluation, null);
    
        TextView evaluationSummary = (TextView) layout.findViewById(R.id.evaluation_summary);
        evaluationSummary.setText(evaluation.getEvaluationSummary());
    
        ((ViewPager) collection).addView(layout);
    
        return layout;
    }
    
    @Override
    public void destroyItem(View collection, int position, Object view) {
         ((ViewPager) collection).removeView((View) view);
    }
    
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    

    So for the page that is displayed, I get the data from my evaluations list using the position as the index.
    Then inflate the Layout which has the views I will add my data too.
    Then I get the TextView to set the evaluation summary text on.
    Then the whole Layout is added to the ViewPager.
    And finally the Layout is also returned.

    If you still can’t get it post your code.

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

Sidebar

Related Questions

So far I have been using in tutorials, examples and sample code only packages
as far as I can get gowalla auth code response contains both expires_at and
So far I have been suggesting new features to http://delphi.uservoice.com Since it is managed
So far all the sites I have made have been in PHP, I'm thinking
So far, my experience in web design has been with very small scale sites
As far as I've been able to find out, Windows doesn't offer an API
As far back as I remember ~1997, web browsers have been very literal in
So far, I have been using a stable release of django: 1.3, and my
As far as I've been able to find, there seems to be one option
Far as best practices are concerned, which is better: public void SomeMethod(string str) {

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.