Common footer layout in all activities - android

I am developing a local music player application in which I am having a common view (player) that has four button (play, pause, previous and next).
I need to use that view in all activities ie. song list, album list, artist list.
In sort user should be able to operate player from all screens.
One way is to create a common activity and extends that activity in all actvity and inflate player layout but in this case i have to implement click events in all activities.
what is the best way to implement this.
many thanks.

The best approach to this is by using Fragments. Create a fragment which connects to the service and provides an UI to control it, then add this fragment to all the activities where you need it or add the activity to a parent activity and extend it by using inheritance in all the child activities.

Make a footer layout file and then use include in all layout file you want to display that footer,
<include layout="#layout/footer" />
use weightSum to manage height of footer in all screen
OR
you can also try switching activities without animation.

Related

should i use a Fragment or an Activity for an ever present View in my Android App?

im developing an application with multiple screens using activities and fragments. The principle behind my decisions to use one or the other are based on the interaction in the application.
I have come to the conclusion that you should use an activity whenever major UI elements remain present after an event has occurred that forces the views inside the UI to change (An example of this can be a tabhost nested in the toolbar styled as the Google Play store android App with multiple fragments as childs. Another example is fragments representing the different rows or clickable elements on a navigation drawer).
So right now im presented with the dilemma of choosing once again between the two (fragment or activity) for a UI element that is going to be present across my whole application. Its triggered by a floating action button that launches a creation tool for an element inside my application and i needed to be accesible across all of my apps screens.
So to sum things up, what i need to know if its better to use a fragment or an activity for an element that is ever present across my whole application.
Thanks in advance
Use Fragments or a compound Views. But both in the right way.
Fragments are thought for reusable combinations of views. Compound Views are Layouts containing views. They are the right way if you want to create views from more primitive views, for example a View containing TextView and a increment- and decrement-button.
Fragments are more Activity-like. They have a real lifecycle. Your description looks like you want to create acitivity-parts. And thats exactly what fragments do.
A Fragment represents a behavior or a portion of user interface in an
Activity. You can combine multiple fragments in a single activity to
build a multi-pane UI and reuse a fragment in multiple activities.
Taken from Android SDK Documentation: Fragments.

How can I add multiple activity to the same screen in android

I want to divide my screen into four parts and add activities in each part. I am not interested in using fragment. Each activity should behave independent of other. Attached photo is showing what I exactly want to do.
In each child activity I want to add VideoView or WebView depending on the selection from menu item.
How can I do it. I didn't find any way to add activity to an activity.
Thanks :)
PS: Activity means Activity not fragment.
i strongly recommend 'using fragments' in your case as ActivityGroup is deprecated in API 13..
The only way you can do it by using fragments. Here is the simple example on how to add multiple fragments on single activity Link
Edit link
You can achieve this design by using four fragments, one for each child view inside a single activity.
The recommended way is to create a single XML layout for your activity, and create four fragments inside that layout.

Android: Using fragments

Is it possible to disable an activity elements when it loads a fragments?
I have a program which has an activity and two fragments. I put a container in activity. When I put two buttons in activity and load each fragment by clicking the button, fragment loads on the activity, but when I click in the position of buttons which are under fragment(or in the large screen next to it), they do some actions, however I don't like it. The buttons should not be clickable.
As a simple solution I create a third fragment and put my buttons in it and load it as a default view in the activity.
I was wondering is it possible to do this without using third fragment.
If you do not want clicks to propagate to below layers you can specify android:clickable="true".
In your case define android:clickable="true" in the bottom layout of your fragments layout xml file to stop any clicks to the activity below.
mach's solution is great, but i can suggest a solution that will be helpful if you want to do more actions in the future than just disabling buttons.
You can simply have your activity implement an Interface "OnFragmentLoaded" for example which has a single method onLoaded()
and in your fragment in your onAttach(Activity ac) method you can do the following
((OnFragmentLoaded) ac).onLoaded()
and you activity would implement onLoaded() to do what ever you want

Navigation tabs with fragments to which to add another fragment

I have a recording app which I recently convert it on tabs layout. One tab is called Recorder and the other one is called Player. Both are integrated in a SherlockFragmentActivity. Each tab represent a fragment with its own layout. The Player fragment has a list with recordings and clicking on an item will open another activity which plays the recording.
All I want is to get rid of that activity and to incorporate a player control directly in the Player fragment. Basically I want to add another fragment in the player fragment (at bottom of the recordings list I want to add a fragment with play, pause, stop, etc buttons). Is it a good practice to add a fragment into another one? If not, how should I add that player control panel?(without simply adding the buttons in the same layout as the list is).
Is it a good practice to add a fragment into another one?
Sure if you decide that you want this, that's why nested fragments have been introduced on the platform. Based on your situation and due to the use of fragments as tabs I wouldn't use a nested fragment, I would just insert the controls in the fragment's layout and change the visibility for that part as the user plays/stops stuff.

Keep footer for multiple activities

I'm creating an app which requires the footer to remain constant among various activities. That is, when animating to another activity, the footer doesn't animate with it - it stays there. Here is an example of what I mean: http://www.youtube.com/watch?v=EwXjdTvVXHQ&feature=related
I know it's an awesome app, but please don't forget my question ;)
Use Fragments to switch out your content, then you can keep one activity with the same footer. Fragments are backported all the way to Donut.
Use only one activity with footer and body in your app, switches and animates body only just like switches in activities.
Create a dummy class that extends an Activity and add footer to it.using xml (or the sameway you would do for other activity).
And extend this class in your app wherever you want footer.

Categories

Resources