我創建了我的TabLayout,並且當我設置爲從我的主類加載的第一個屏幕時,它工作正常。我按照這裏的教程:http://joshclemm.com/blog/?p=136Android TabHost-從一個按鈕打開一個新的TabLayout點擊
但是,我不希望它是第一件事加載。
我有一個應用程序splashscreen
,然後去home
屏幕沒有標籤。它有一堆按鈕。然後,當您點擊其中一個按鈕時,我想加載放置在tabgroup
中的該視圖,然後您有常規選項卡單擊。 任何想法如何在Android上做這個基本的東西?
我不斷收到運行時異常錯誤。
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)'
這是我的onCreate
方法代碼。
我有一個按鈕,名爲Transfers
,當它被點擊時,Transfers.class activity
,這是一個tablayout應該打開,但沒有。該活動位於Android清單中。我是一個noob,所以我知道我可能在這裏做了一件很簡單的事情。
幫助將不勝感激!
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);
}
});
這是我的Android清單
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="ttj.android.ft.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Transfers"
android:label="@string/app_name" >
<intent-filter>
<action android:name="ttj.android.ft.TRANSFERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
這裏是logcat的日誌時崩潰。
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)
傳遞活動代碼
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);
}
固定
我的課TransfersTeams和TransfersSummary正在擴展TabActivity。我將其更改爲「活動」,現在可以使用。
對不起,我應該完全分享清單。我已經有了初始頁面的主要意圖。我編輯了我的帖子以包含完整的清單。 – tiptopjat