Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TabHost- Opening a new TabLayout from a button click
    primarykey
    data
    text
    <p>I have created my TabLayout, and it works fine when I have set up to be the first screen to load from my main class. I followed the tutorial here: <a href="http://joshclemm.com/blog/?p=136" rel="nofollow">http://joshclemm.com/blog/?p=136</a></p> <p>However, I don't want it to be first thing to load.</p> <p>I have an application with a <code>splashscreen</code>, then go to a <code>home</code> screen with no tabs. It has a bunch of buttons on it. When you then click one of the buttons I want to load that view which is placed in a <code>tabgroup</code> and then you have regular tabs to click around. Any ideas how to do this basic thing on Android?</p> <p>I keep getting a Runtime exception error.</p> <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{ttj.android.ft/ttj.android.ft.Transfers}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)' </code></pre> <p>Here is my <code>onCreate</code> method code.</p> <p>I have a button called <code>Transfers</code>, when it is clicked the <code>Transfers.class activity</code>, which is a tablayout should open but doesn't. The activity is in the android manifest. I'm a noob, so I know I'm probably doing something very simple wrong here. </p> <p>Help would be greatly appreciated!</p> <pre><code>public class MainActivity extends Activity { Button Records, Transfers, Leagues; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Transfers = (Button) findViewById(R.id.bTransfers); Transfers.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent openTransfers = new Intent(MainActivity.this, Transfers.class); startActivity(openTransfers); } }); </code></pre> <p>Here is my Android Manifest</p> <pre><code> &lt;activity android:name=".Splash" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="ttj.android.ft.STARTINGPOINT" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".Transfers" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="ttj.android.ft.TRANSFERS" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>Here is the log from logcat when it crashes.</p> <pre><code>FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'? at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'? at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680) at android.widget.TabHost.setCurrentTab(TabHost.java:346) at android.widget.TabHost.addTab(TabHost.java:236) at ttj.android.ft.Transfers.onCreate(Transfers.java:52) at android.app.Activity.performCreate(Activity.java:4465) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) </code></pre> <p>Transfer Activity code</p> <pre><code>public class Transfers extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.m_transfers); TabHost mTabHost = getTabHost(); Intent intentTeams = new Intent().setClass(this, TransfersTeams.class); TabSpec teamsTab = mTabHost.newTabSpec("TEAMS").setIndicator("") .setContent(intentTeams); Intent intentSummary = new Intent().setClass(this, TransfersSummary.class); TabSpec summaryTab = mTabHost.newTabSpec("SUMMARY").setIndicator("") .setContent(intentSummary); mTabHost.addTab(teamsTab); mTabHost.addTab(summaryTab); mTabHost.setCurrentTab(0); } </code></pre> <p><strong>FIXED</strong></p> <p>My classes TransfersTeams and TransfersSummary were extending TabActivity. I changed this to Activity and it works now.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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