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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:54:49+00:00 2026-06-13T19:54:49+00:00

I am developing application using viewpager with fragment.In my application i have a items

  • 0

I am developing application using viewpager with fragment.In my application i have a items which i showing in List.After that when i click i have calling SherlockFragmentActivity which calling ViewPager with adapter.Now the problem is getItem in FragmentPagerAdapter give multiple position at a single time.Also when i flip backword then also giveing wrong position.Here is my code

ViewPager Code:-

private void initialisePaging() {
            //Adapter Context;
    this.mPagerAdapter = new MyPagerAdapter(
            super.getSupportFragmentManager(), getApplicationContext(),
            title, link, description);


    ViewPager pager = (ViewPager) super.findViewById(R.id.viewpager);
    pager.setAdapter(this.mPagerAdapter);
           //Take position from ListView & set postion .
    pager.setCurrentItem(post_position);
}

My Adapter Class which responsible for set fragment:-

Problem:- The problem is getItem Calling 3 time & suppose i click on 4 item its giving me 3,4,5 number.

public MyPagerAdapter(FragmentManager fm, Context cont,
            ArrayList<String> title, ArrayList<String> link,
            ArrayList<String> description) {

             super(fm);
    this.context = cont;
    this.key_desc = description;
    this.key_link = link;
    this.key_title = title;
    viewPagerApplication = (RssItem) cont;

}

@Override
public Fragment getItem(int position) {
        return Fragment0.newInstance(position, this.context, key_title,
            key_link, key_desc);
}

@Override
public int getCount() {
     return key_title.size();
}
My Fragment Class:-

Problem:-Here if i show postion in textview its correct position but if i want take position in logcat for further parsing its giving me again 4,3,5 number which is also diffrent from getItem();

public static Fragment0 newInstance(int num,Context cont, ArrayList<String> key_title, ArrayList<String> key_link, ArrayList<String> key_desc) {
    context=cont;



    Fragment0 f = new Fragment0();
    Bundle args = new Bundle();
    args.putInt("num", num);
    f.setArguments(args);

    return f;
}


 public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);






 };

   public int getShownIndex() {
       return getArguments().getInt("num", 0);
   }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
         View v = inflater.inflate(R.layout.newsdetailfragment_screen, container, false);
          tv = v.findViewById(R.id.headingtextview_id);
         ((TextView)tv).setText(String.valueOf(getShownIndex()));
          ((TextView)tv).setTextColor(Color.BLACK);
         ((TextView)tv).setTextSize(20);
           return v;
    }

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
}

Now kindly let me know where i am wrong & how can i get only one exact position for further process.

  • 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-13T19:54:50+00:00Added an answer on June 13, 2026 at 7:54 pm

    Inside of getItem(), the position parameter is the position that is in need of rendering. It is NOT the position of the currently focused item that the user would see. The pages to the left and right of the currently displayed view need to be pre rendered in memory so that the animations to those screens will be smooth. To get the item at current position use:

    pager.getCurrentItem();
    

    If you need an actual position of the page you can implement onPageChangeListener

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
    }
    

    position in onPageSelected will give an accurate current position of the page.

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

Sidebar

Related Questions

I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I'm developing an application using the WAF (WPF Application Framework) which is based on
I'm developing an application using MS Visual C# 2008 Express that uses the ClickOnce
I am developing demo application in which I am using view pager. Now I
Developing iphone application using makkit framework. I have got the map view integrated in
I am considering developing an application using Ruby on Rails that is a planner
I'm developing an Android 3.1 Tablet application using android.support.v4.view.ViewPager and android.support.v4.app.FragmentActivity . The following
I am developing an MVC3 application using Visual Studio 2010. I have an aspx
Basically I'm developing application using asp.net and I want to write Custom validator which
I'm developing application using VC++ 6. I have a 3rd party DLL. This library

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.