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

  • Home
  • SEARCH
  • 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 9186765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:36:43+00:00 2026-06-17T19:36:43+00:00

I’m new fairly new to Android programming , so go easy on me. :-)

  • 0

I’m new fairly new to Android programming, so go easy on me. 🙂

I have a list of items, when the user clicks on an item it takes them to a screen with that item details. User can swipe right and left to view the details of other items on the list.
I have some ActionBar icons like share, increase font size …etc
My problem is: If I choose item1 on the list and go to screen with the details of that item, if I swipe to item2 then click share, the contents of item1 are shared instead of item2.
Same thing happens to increasing or decreasing the font. If I choose item2 then swipe to item3 and increase font size the font size of item2 increases instead of item3.
I tried a lot of things like using SimpleOnPageChangeListener but no use, I don’t know how to implement it correctly.

Here is my code:

Main activity which contains the listview:

    public class Main extends SherlockListActivity implements OnItemClickListener {

        @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);  

            ListView mylist = (ListView) findViewById(android.R.id.list);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simple_list_reda_1, R.id.list_content, getResources().getStringArray(R.array.items_list_array) );
            mylist.setAdapter(adapter);

            mylist.setOnItemClickListener(new OnItemClickListener() 
            {
                public void onItemClick(AdapterView<?> arg0,View arg1, int position, long arg3) 
                {
                    Intent n = null; 
                switch (position){
                    case 0: 
                        n = new Intent(getApplicationContext(), ViewPagerClass.class);
                        n.putExtra("POSITION_KEY", position);
                        break;
                    case 1: 
                        n = new Intent(getApplicationContext(), ViewPagerClass.class);
                        n.putExtra("POSITION_KEY", position);
                        break;
                    case 2: 
                        n = new Intent(getApplicationContext(), ViewPagerClass.class);
                        n.putExtra("POSITION_KEY", position);
                        break;
                    case 3: 
                        n = new Intent(getApplicationContext(), ViewPagerClass.class);
                        n.putExtra("POSITION_KEY", position);
                        break;
                    }

                    if(null!=n)
                        startActivity(n);
                }
            });     
        }
    }

ViewPagerClass:

    public class ViewPagerClass extends SherlockFragmentActivity{

        static final int NUM_ITEMS = 4;
        MyAdapter mAdapter;
        ViewPager mPager;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.setContentView(R.layout.viewpager_layout);

            mAdapter = new MyAdapter(getSupportFragmentManager());
            mPager = (ViewPager) findViewById(R.id.viewpager);
            mPager.setAdapter(mAdapter);
            //mPager.setCurrentItem(2);

                final ActionBar ab = getSupportActionBar();
                ab.setDisplayHomeAsUpEnabled(true);
                ab.setDisplayUseLogoEnabled(false);
                ab.setDisplayShowHomeEnabled(false);
    }

 public boolean  onCreateOptionsMenu(Menu menu) {

        mainMenu = menu;
        subMenu1 = menu.addSubMenu(0, 1, 7, "");
        subMenu2 = menu.addSubMenu(0, 2, 6, "");
        subMenu3 = menu.addSubMenu(0, 3, 5, "");

        //some code here...

        MenuItem share = menu.findItem(R.id.menu_share);
        ShareActionProvider provider = (ShareActionProvider) share.getActionProvider();
        provider.setShareHistoryFileName(null);
        provider.setShareIntent(createShareIntent());

        getSupportMenuInflater().inflate(R.menu.textsize_subm, subMenu3);
        MenuItem subMenu3Item = subMenu3.getItem();
        subMenu3Item.setIcon(R.drawable.ic_font_size);
        subMenu3Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        return true;


    }


    private Intent createShareIntent() {

        TextView tv = (TextView) findViewById(R.id.textView1);
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_TEXT, tv.getText());
        shareIntent.setType("text/plain");      
        return shareIntent;
    }


           @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            //some code here...

            default:
                return super.onOptionsItemSelected(item);
        }
    }



    public static class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

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

        @Override
        public Fragment getItem(int position) {

            switch(position){
            case 0: return FirstPageFragment.newInstance();

            case 1: return SecondPageFragment.newInstance();

            case 2: return ThirdPageFragment.newInstance();

            case 3: return FourthPageFragment.newInstance();

            }
            return null;
        }
    }



    public static class FirstPageFragment extends Fragment {

        public static FirstPageFragment newInstance() {
            FirstPageFragment f = new FirstPageFragment();
            return f;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View V = inflater.inflate(R.layout.fragment1, container, false);
            return V;

        }
    }

    public static class SecondPageFragment extends Fragment {

        public static SecondPageFragment newInstance() {
            SecondPageFragment f = new SecondPageFragment();
            return f;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View V = inflater.inflate(R.layout.fragment2, container, false);
            return V;

        }
    }

    public static class ThirdPageFragment extends Fragment {

        public static ThirdPageFragment newInstance() {
            ThirdPageFragment f = new ThirdPageFragment();
            return f;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View V = inflater.inflate(R.layout.fragment3, container, false);
            return V;

        }
    }


    public static class FourthPageFragment extends Fragment {

        public static FourthPageFragment newInstance() {
            FourthPageFragment f = new FourthPageFragment();
            return f;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View V = inflater.inflate(R.layout.fragment4, container, false);
            return V;

        }
    }

So in short: The menu/actionbar icons won’t update to respond to the current page after swiping.
I hope my question is clear.

  • 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-17T19:36:44+00:00Added an answer on June 17, 2026 at 7:36 pm

    I figured it out, so I thought I’d post here in case anyone ran into the same problem.
    The solution is quite easy actually, I don’t know why I didn’t figure it out right away.

    I used ‘setOnPageChangeListener’ & put it in ‘onCreate’

    Here is my code:

        int pageNum;
        myPager.setOnPageChangeListener(
                        new ViewPager.SimpleOnPageChangeListener() {
                            @Override
                            public void onPageSelected(int position) {
                                //Here I put the code I want to call/update when the page changes (i.e swipe)
                                    pageNum = myPager.getCurrentItem();
    
                                //update actionprovider & share intent after swiping
                                    ShareActionProvider mShareActionProvider = (ShareActionProvider) item.getActionProvider();
                                    mShareActionProvider.setShareIntent(createShareIntent());        
                                //I can also put a switch statement here, depending on which page. 
                                    switch (pageNum) {
                                    case 0: //.....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.