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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:15:19+00:00 2026-06-14T08:15:19+00:00

I have a MainActivity which contains a tab bar with two fragments: MainFragment and

  • 0

I have a MainActivity which contains a tab bar with two fragments: MainFragment and WishlistFragment. They both extend as ListFragment.

When someone touches a menu item from the Option menu, I want the ListView within the Fragment that is showing to refresh its list using its custom adapter called LazyAdapter adapter.

So in here is where I want the refresh to go in my MainActivity code:

public boolean onOptionsItemSelected(MenuItem item) {   
     switch (item.getItemId()) {
        case R.id.menu_edit:

               // find out which fragment is showing here
               // refresh the fragment's listview here
               // adapter.notifyDataSetChanged();

               return true;
        }
}

How can I do this? I am not sure how to call forward into the fragment and how to determine which fragment is showing.

Here is how I have my tabs set up in MainActivity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    actionBar.addTab(actionBar.newTab().setText("Main").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Wishlist").setTabListener(this));
}

public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    // When the given tab is selected, show the tab contents in the container
    ListFragment newfragment = null;

    switch (tab.getPosition() + 1)
    {
    case 1:
        newfragment = new MainFragment();
        break;

    case 2:
        newfragment = new WishlistFragment();           
        break;
    }

    getSupportFragmentManager().beginTransaction()
            .replace(R.id.container, newfragment)
            .commit();
}
  • 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-14T08:15:20+00:00Added an answer on June 14, 2026 at 8:15 am

    How can I do this?

    Step #1: Fix your implementation of onTabSelected(). You do not want to be creating a new fragment each time the user chooses a tab. Instead, you want to have two fragments, held onto by the activity in data members, and use those in the replace() transaction.

    Step #2: When needed, call getSelectedNavigationIndex() on the ActionBar, use that to choose which of the two fragments you need (obtained from the data members mentioned in Step #1 above), and call some method on the fragment to do what you want.

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

Sidebar

Related Questions

So, in my program i have a TabActivity which contains two tabs, one tab
I have an activity ( MainActivity.java ) in which content view is like this
I have a Tabhost which is my main activity. When a tab is clicked
Here's the problem. In my app, I have 5 tabs which contains activities. In
I have a mainActivity which is Customer.java with listview of 5 diff. activities. I
I have an activity which contains only ScrollView and a TableLayout in it. In
In my main activity I have a spinner which contains three categories(All,Horizontal and Vertical),
I have main activity which contains few radio buttons. Their is one button named
I currently have a listview which contains a couple of strings. These are called
I have an application that contains a main Activity, which has a very simple

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.