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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:14:25+00:00 2026-05-26T23:14:25+00:00

I have a hard time getting fragments to update their views… Specifically, fragments that

  • 0

I have a hard time getting fragments to update their views… Specifically, fragments that exist in a ViewPager with ActionBarSherlock.

Here is my fragment class:

public class SearchFragment extends Fragment{
private String mInterests;
private String mSentence;

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

@Override
public void onResume() {
    super.onResume();
    getUserInterests();
}

/*
 * Get the users interests from the underlying
 * data store.
 */
public void getUserInterests() {
    TextView tv = (TextView) getView().findViewById(R.id.bounty_search_txtResult);
    DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
    SQLiteDatabase db = dbHelper.getReadableDatabase();

    Cursor cursor = db.query(DatabaseConstants.TABLE_NAME, null, null, null, null, null, null);
    cursor.moveToFirst();
    mInterests = cursor.getString(cursor.getColumnIndex(DatabaseConstants.INTERESTS));
    if(mInterests.length() == 0) {
        mSentence = "You have no interests.";
    }
    else {
        mSentence = "Your interests are: ";
        mInterests = cursor.getString(cursor.getColumnIndex(DatabaseConstants.INTERESTS));
    }
    tv.setText(mSentence + mInterests);
    cursor.close();
    db.close();
    dbHelper.close();
}
}

The way I’m calling this fragment from my FragmentActivity is in the following…

SearchFragment searchInterests = new SearchFragment();

My views in the fragment are properly setup when it first runs, but when I call something like…

searchInterests.update();

from the FragmentActivity, to update some views,the getView() of

TextView tv = (TextView) getView().findViewById(R.id.results);

returns null and fails. I’m struggling to understand why this is.. Someone had mentioned to me that It’s because my Fragment is not attached to anything… I don’t quite understand this part and not only that but I just dont understand why getView() points to null if onCreateView was successful the first time? Doesn’t getView() gets the View returned by onCreateView? Here is the full code set: https://gist.github.com/1369653

  • 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-26T23:14:26+00:00Added an answer on May 26, 2026 at 11:14 pm

    So after some time, I figured it out… Problem was coming from how the FragmentPagerAdapter was returning the fragment…

    @Override
    public Fragment getItem(int position) {
        return Fragment.instantiate(mContext, mTabs.get(position), null);
    }
    

    This was returning a NEW fragment each time getItem() was called. However, I also had…

    searchInterests = new SearchFragment();
    selectInterests = new SelectFragment();
    

    Which was creating a new fragment before it was added to the adapter. So the adapter was receiving a new fragment AND returning a new fragment instead of returning the same one I gave it. So I simply changed the getItem() function to return a NEW fragment if none of the same class already exist.

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

Sidebar

Related Questions

I have a malformed page to scrape, and have had a hard time getting
I am having a really hard time getting this to work. I have two
I have a hard time figuring this one out, it's about mistakes that can
I seem to have a hard time getting my head around this. What's the
I am using jquery layout and I have a very hard time getting rid
I'm having hard time getting this snippet to work. I have made a minimal
i've been reading from the file and i have hard time getting rid of
I have a hard time getting started with a simple bluetooth example which has
Anyone have any examples of javascript actionresults? I am having a hard time getting
I'm having a hard time getting better results on this query: I have 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.