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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:20:21+00:00 2026-06-12T14:20:21+00:00

Here is my view pager adapter to load fragments. Inside the getItem() method, I

  • 0

Here is my view pager adapter to load fragments. Inside the getItem() method, I am trying to insert the values dynamically using the index passed to that function. I have all the data inside productData. But it always fetches the value of

 productData.get(0).get("name")

into all the fragments. The index value is correctly being passed into fragments. I verified it. And also the data inside the productData is also correct. Where is the issue here?

  public class ProductViewPagerAdapter extends FragmentPagerAdapter {
    public ProductViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }
    @Override
    public Fragment getItem(int i) {            
        Fragment fragment = new ProductViewFragment();
        Bundle args = new Bundle();
        args.putInt("number", i + 1);
        args.putString("name", productData.get(i).get("name"));
        fragment.setArguments(args);
        return fragment;
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0: return "test1";
            case 1: return "2";
            case 2: return "3";
            case 3: return "4";
        }
        return null;
    }     

 }
  • 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-12T14:20:22+00:00Added an answer on June 12, 2026 at 2:20 pm

    The problem is that you only have a single HashMap. Even though you keep changing the data inside the HashMap, the list productItems just contains 10 references to the single HashMap. So in the end, it will contain 10 copies of the final set of data.

    What you want to do is create a new HashMap for each loop iteration. Here’s the modified code:

    public ArrayList<HashMap<String,String>> getData(AsyncTask<Void, Void, Void> asynctask, String query) throws URISyntaxException
    {
        api_url += query;
        //  Log.v("API url",api_url);
        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(api_url); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element
        NodeList nl = doc.getElementsByTagName(KEY_PRODUCT);
        ArrayList<HashMap<String, String>> productItems = new ArrayList<HashMap<String, String>>();
        for (int i = 0; i < 10; i++) {
            Element e = (Element) nl.item(i);           
            // adding each child node to HashMap key => value
            HashMap<String, String> map = new HashMap<String, String>();
            map.put(KEY_PROD_NAME, e.getAttribute(KEY_PROD_NAME));
            map.put(KEY_ID, e.getAttribute(KEY_MER_ID));
            map.put(KEY_PRICE, e.getAttribute(KEY_MER_PRICE));      
            Log.v("fsd:",e.getAttribute(KEY_PROD_NAME));
            // adding HashList to ArrayList
            productItems.add(map);      
        }       
        return productItems;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create fragments inside viewpager. In the adapter I am using
I using coda slider in my page. View it here: http://www.ndoherty.com/demos/coda-slider/1.1.1/ Each tab causes
I have a view pager which contains a fragment. When the fragment pager adapter
I am Using View Pager to Display three Views. Filter,Streets,Around Each View is Defined
I need to get page indicator in the view pager file with images. Here
I'm trying to follow Google's tutorial for implementing a ViewPager with Fragments using the
I'm using a pager adapter successfully but would like to know how to add
Here is my onCreate() method. I am trying to pass a variable from one
I am trying to create a swipping tab view using the ActionBar in Mono
This question already has an answer here: view sql that linq-to-sql produces 3 Answers

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.