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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:09:05+00:00 2026-05-28T19:09:05+00:00

I have a ViewPager and it is using a FragmentAdapter in order to display

  • 0

I have a ViewPager and it is using a FragmentAdapter in order to display several fragments of the same kind. Although these Fragments are basically instantiated from the same class, they are using a ListView to display different information. (Obviously the ListView is being poulated by an ArrayAdapter.)
A background service is also running and is constantly receiving data from the Internet. I want to be able to update a specific Fragment in the ViewPager when my background service has notified me of a specific event.
How can I do that?
A code snippet would be hugely appreciated!

(By the way, I have saw this similar question but I have no idea how to use their suggestion!)

To make it all more simple:
My activity with the ViewPager:
[Fragment 0] [Fragment 1] [Fragment 2]

The background service tells me (via a broadcast) to update the ListView in Fragment 1.

EDIT:
Here are sample codes:

public class ChatWindowPager extends FragmentActivity
{
    private ViewPager mViewPager = null;
    private ChatFragmentAdapter mAdapter = null;
    @Override
    protected void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chat_window_pager);

        this.mViewPager = (ViewPager) findViewById(R.id.chatPager);
        this.mAdapter = new ChatFragmentAdapter(getSupportFragmentManager());
        this.mViewPager.setAdapter(this.mAdapter);
        .
        .
        .
    }
    
    class ChatFragmentAdapter extends FragmentPagerAdapter implements ViewProvider
    {

        public ChatFragmentAdapter(final FragmentManager fm)
        {
            super(fm);
        }

        @Override
        public Fragment getItem(final int arg0)
        {
            String friendId = ..... // Some initializations
            ChatWindowFragment f = ChatWindowFragment.newInstance(friendId);
            return f;
        }

        @Override
        public int getCount()
        {
            ...
        }

        @Override
        public View getView(final int position)
        {
            View v = getLayoutInflater().inflate(R.layout.tab_holder, null);
            .
            .
            .
            return v;
        }
    }
}

Now the fragments is defined like this:

public class ChatWindowFragment extends Fragment
{
    public String friendId;
    private ListView lv;
    
    public static ChatWindowFragment newInstance(final String friendId)
    {
        ChatWindowFragment chatWindowFragment = new ChatWindowFragment();
        Bundle bundle = new Bundle();
        bundle.putString("friendId", friendId);
        chatWindowFragment.setArguments(bundle);
        return chatWindowFragment;
    }

    @Override
    public void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.friendId = getArguments().getString("friendId");
    }

    @Override
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
    {
        View v = inflater.inflate(R.layout.chat_window, container, false);

        this.friendId = getArguments().getString("friendId");
        .
        .
        .
        return v;
    }
    
    //The rest of the class

}

As I am using a FragmentPagerAdapter I don’t see how I can set the tag of each fragment!
(Obviously, I am not using transactions to add the Fragments!)

EDIT 2:
I would like to know whether what I’m doing, is the correct way to handle what I want to do… Any other solution is also welcome!

  • 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-28T19:09:06+00:00Added an answer on May 28, 2026 at 7:09 pm

    Try this,

    Register a broadcast receiver in all your fragments… like this

    create a class which extends a broadcast receiver in all the classes, for eg:

    public class FragmentReceiver1 extends BroadcastReceiver {
            @Override
            public void onReceive(Context context, Intent intent) {
            }    
    }
    

    and register this receiver in you fragment’s onCreate …

    for eg. getActivity().registerReceiver(new FragmentReceiver1(), new IntentFilter("fragmentupdater"));

    Now assign a unique id to each of you fragment like 1 for Fragment1, 2 for Fragment2 and likewise

    now whenever you want to pass any data and update any of the fragment just send a broadcast with the data in intent and “fragmentupdater” as the intent-filter…

    For eg:

    Intent data = new Intent("fragmentupdater");
    data.putString("key","data");
    data.putInt("fragmentno",1); // Pass the unique id of fragment we talked abt earlier
    activity.sendBroadcast(data);
    

    Now each of your fragment will receive the data but you can verify if the data if for the same fragment by the unique id we passed in it in the onReceive function…, the intent which you get, is the intent we passed above

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

Sidebar

Related Questions

I have a FragmentActivity using a ViewPager to serve several fragments. Each is a
I have a project using a ViewPager which works correctly: I can page from
I'm using the ViewPager from the compatibility library. I have succussfully got it displaying
I have the following problem. I have a tabbed application implemented using a ViewPager.
I have a ViewPager with multiple fragments. In one Fragment I play audio. When
I have a ViewPager with 3 fragments into it. Everything works fine with two
I have a textview inside ViewPager . I am using PagerAdapter to show the
I have the following structure in my app: FragmentActivity with ViewPager holding multiple fragments
I am using the ViewPager from the Android Support package (android.support.v4.view.ViewPager). My ViewPager layout
I am using fragments to show images/pages.I have one Activity(Main) which contains all the

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.