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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:54:10+00:00 2026-05-26T02:54:10+00:00

I am using a tabhost in my application with 3 tabs associated with 3

  • 0

I am using a tabhost in my application with 3 tabs associated with 3 different activities. Inside each of the activities, I need to add a fragment(the fragment contains a video player which plays video from web). Below is the code of the activity which adds the fragment.



    public class FilmsActivity extends Activity {

        @SuppressWarnings("unused")
        private static final String TAG = "FilmsActivity";

        private static FragmentManager mFragmentManager;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Log.i(TAG, "Films onCreate ");
            mFragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
            // get a video fragment. Title and URI as the constructor arguments
            VideoViewer vvFragment = VideoViewer.newInstance("Testing",Uri.parse("http://daily3gp.com/vids/747.3gp"));
            Log.i(TAG, "Films onCreate 1");
            VideoViewer vvFragment = VideoViewer.newInstance("Testing",Uri.parse("/sdcard/family_guy_test.3gp"));
            Log.i(TAG, "Films onCreate 2");
            fragmentTransaction.add(android.R.id.tabcontent, vvFragment, "videoFragment");
            Log.i(TAG, "Films onCreate 3");
            fragmentTransaction.commit();
        }
    }

The fragment implementation is as shown below.



        public class VideoViewer extends Fragment {
        // Debug vars
        @SuppressWarnings("unused")
        private static final String TAG = "VideoViewer";
        private static final Boolean DBG_TOAST = false;
        private static final Boolean DBG_LOG = false;

        // Video Title, URL of the Video will be unique for each video. Save it in a member variable.
        private static final String VIDEO_TITLE = "title";
        private static final String VIDEO_URI = "uri";
        // Different states of the video viewer
        private static final int STATE_PAUSED = 0;
        private static final int STATE_PLAYING = 1;
        private static final int STATE_STOPPED = 2;
        // The view which holds the video player
        private VideoView mVideoView;
        // The transparent layout above the video which will be shown when it is paused and made not 
        // visible when the video is playing 
        // The title of the video is in the textview
        private TextView mVideoTitle;
        // UI Control Elements from the view.
        private ImageButton mPlayPauseButton;
        private Button mShareButton;
        private Button mAddToFavourites;
        // This holds the current state of the Video Viewer
        private int mVideoState;

        public static VideoViewer newInstance(String VideoTitle, Uri VideoUri) {
            VideoViewer VV = new VideoViewer();
            Bundle args = new Bundle();
            // Put the title and the uri in the bundle
            args.putString(VIDEO_TITLE, VideoTitle);
            args.putString(VIDEO_URI, VideoUri.toString());
            // Later on convert the string to Uri using uri.parse(string)
            return VV;
        }

        /* Return the view that is used by the fragment */
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            // Check if you want to use container or don't want to use anything
            return inflater.inflate(R.layout.fragment_video_viewer, null);
        }

        /* Initialize the variables here, retrieve views and  */
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            // Assignment for the local variables
            mVideoView = (VideoView) getView().findViewById(R.id.fragment_video_viewer_video);
            mVideoTitle = (TextView) getView().findViewById(R.id.fragment_video_viewer_title);
            // Use the video title as the Text in the TextView
            mVideoTitle.setText(getArguments().getString(VIDEO_TITLE));
            // Get the URL from the argument bundle
            Uri videoUri = Uri.parse(getArguments().getString(VIDEO_URI));
            videoUri = Uri.parse("http://daily3gp.com/vids/747.3gp");
            // Toast if the URI is null
            if(DBG_TOAST) {
                if (videoUri.toString() == "") {
                    // Tell the user to provide a media file URL/path.
                    Toast.makeText(getActivity().getApplicationContext(), "Uri is null", Toast.LENGTH_LONG).show();
                    // Use a default video
                    // videoUri = Uri.parse("http://daily3gp.com/vids/747.3gp");
                }
            }
            // Initialize a media controller and anchor the videoview to it
            MediaController mediaController = new MediaController(getActivity().getApplicationContext());
            mediaController.setAnchorView(mVideoView);

            mVideoView.setMediaController(mediaController);
            mVideoView.requestFocus();
            mVideoView.setVideoURI(videoUri);
            mVideoView.start();
        }
    }


Can somebody tell me whats wrong with the implementation? An empty Films activity would produce a screen with 3 tabs as expected. However, when I try to run with this implementation, The app is not running at all.

The films activity is called from the mainactivity which creates a tabhost. So, the view for the films activity should go to android.R.id.tabcontent. should I use it when I add the 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-05-26T02:54:11+00:00Added an answer on May 26, 2026 at 2:54 am

    I got the problem fixed. I had to extend FragmentActivity instead of Activity.

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

Sidebar

Related Questions

Is there a possibility to navigate between Activities tabs in TabHost using back button?
I am using the TabHost in my application, I am using four Tabs in
I have an application with TabHost with few tabs and in each tab I
I am using tabs in my application . Each tab is pointing to 3
I'm using the TabHost and TabWidget to create some tabs for an Android application.
I have an application with various tabs (on a tabhost), each tab is an
I`m trying to build a application using the Fragment/Tabs and Pager from the android
I want to reuse my tabs like footer for each activities in my application.
I have created four tabs using tabhost, and placed four listviews in each like
I am using tab host(tabs) in application, it have four tabs on home screen,

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.