Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Simple example (as dave.c suggested):</p> <pre><code>public class BaseActivity extends Activity { public void onClickButton1(View view) { Toast toast = Toast.makeText(this, "Button 1 clicked", Toast.LENGTH_SHORT); toast.show(); } public void onClickButton2(View view) { Intent i = new Intent(this, MyFirstActivity.class); startActivity(i); } public void onClickButton3(View view) { Intent i = new Intent(this, MySecondActivity.class); startActivity(i); } } </code></pre> <p>Your MyFirstActivity will look like:</p> <pre><code>public class MyFirstActivity extends BaseActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_first_activity); } } </code></pre> <p>Your MySecondActivity activity:</p> <pre><code>public class MySecondActivity extends BaseActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_second_activity); } } </code></pre> <p>In my_first_activity.xml layout you include:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:text="My first activity" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/bottom_bar" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>In my_second_activity.xml:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:text="My second activity" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/bottom_bar" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>In bottom_bar you define buttons with onClick handlers:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Button android:text="Button1" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClickButton1"/&gt; &lt;Button android:text="Button2" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClickButton2"/&gt; &lt;Button android:text="Button3" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClickButton3"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>You might run into problems using this design. For example when you want to use ListView in some of your activities and you want to subclass ListActivity (TabActivity is another example) it will be not possible.</p> <p>Another way is to subclass Activity and define one common handler that handles onClick events. In this case you will need to define onClick handlers in each activity and call corresponding common handler's methods.</p> <p>Yet another way is to use TabHost and TabActivity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload