I am creating a music player app the below are list of activities:
The below is MusicPlayActivity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/background">
<include layout="@layout/musicpanel"></include>
</RelativeLayout>
The below code is for musicpanel which is included in MusicPlayActivity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:id="@+id/playPause"
android:layout_gravity="bottom"
android:layout_marginLeft="51dp"
android:layout_marginStart="51dp"
android:layout_alignTop="@+id/stop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:id="@+id/stop"
android:layout_gravity="bottom"
android:layout_marginBottom="28dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/playPause"
android:layout_toEndOf="@+id/playPause"
android:layout_marginLeft="67dp"
android:layout_marginStart="67dp" />
</RelativeLayout>
If the user click back button from MusicPlayActivity we need to display SongListActivity so here I want to display musicpanel.
My question is what is the best practice to create musicpanel?
Right now I am including it in xml but on each activity I need to set listeners for all components of musicpanel (like play, pause, next, previous) every time
Thanks in advance
You have several options:
Usually it's done in 1/2 or 2/3 way as these combinations reduce code duplication and are quite easy to do.