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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:14:18+00:00 2026-06-13T23:14:18+00:00

I have a App with several Fragments which are managed by one Activity. My

  • 0

I have a App with several Fragments which are managed by one Activity. My Problem is that I want to test the Application and test the UI of each Fragment. I can test the first Fragment and get all Views of this, but when I click on a Button or something else (to replace the Fragment with another Fragment) I can’t get any View of the new Fragment, but my MainActivity says that the current Fragment is the new Fragment.

@UiThreadTest
public void testNewFragmentScrollView() {
    assertTrue(mActivity.getFragmentType().equals(FragmentTypes.FRAGMENT_STARTSCREEN));
    ivNewFragment.performClick(); // replace fragment
    sleep();
    assertTrue(mActivity.getFragmentType().equals(FragmentTypes.FRAGMENT_NEW));
    //get something from new fragment, ID is copied from xml file and not false
    ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.sv_fragment_new_scrollable);    
    assertTrue(scrollView != null); //#false???
    mActivity.finish();
}

Do I have to update something in my Testclass or why i’m getting no Views from the new Fragment?

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

    Ok I solved my problem by splitting the code. When I change the Fragment in setUp and wait some ms, I can get all views from the new Fragment in each testmethod

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        setActivityInitialTouchMode(false);
        mActivity = getActivity();
        buNewFragment =(Button) mActivity.findViewById(R.id.bu_actionbar_newfragment);
        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                buNewFragment .performClick();
            }
        });
        sleep(500);//simple Thread.sleep() method
    }
    
    @UiThreadTest
    public void testNewFragmentScrollView() {
        assertTrue(mActivity.getFragmentType().equals(FragmentTypes.FRAGMENT_NEW));
        ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.sv_fragment_new_scrollable);
        assertTrue(scrollView != null); //#t
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app, I have only one Activity which hosts several fragments . The
I have an app that contains several activities...so lets say user is navigating activity
I have an app that have several views. In one view I would like
I have an app which contains a scrollview with several tableviews. Each tableview is
In my application, I have the Activity and several Fragments (Activity works as Controller
I have an app that loads several resources when it's first run, which are
I have an app which consists of several different assemblies, one of which holds
I have an app that lets the user interact with several forms. I can
In my iOS app I have several UIElement s that can process user input:
I have a view controller based app that contains several views that I display/hide

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.