1

我有三個標籤,我想用它來利用我的三個網頁瀏覽來顯示特定的域。一切都建立發現,但是當我嘗試啓動程序的時候,力當我運行它&如果我調試它關閉 - 它保持與開放的佈局和視圖(在調試的時候它基本上什麼都不做。)如何在選項卡中使用WebView並調用「(LocalActivityManager activityGroup)」?

logcat的說

無法啓動活動ComponentInfo {com.company.client/com.company.client.MainActivity}:java.lang.IllegalStateException:你忘了叫 '公共無效設置(LocalActivityManager的ActivityGroup)' **

我該如何稱呼?

繼承人我的代碼:

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 

public class MainActivity extends Activity { 
TabHost th; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    th = (TabHost) findViewById(R.id.tabhost); 
    th.setup(); 


    TabSpec firstSpec=th.newTabSpec("Classes & Events"); 
    firstSpec.setIndicator("Classes & Events", null); 
    Intent firstIntent= new Intent(this, WebViewActivity.class); 
    firstIntent.putExtra("backswipe", false); 
    firstSpec.setContent(firstIntent); 
    th.addTab(firstSpec); 

    TabSpec secondSpec=th.newTabSpec("Twitter"); 
    secondSpec.setIndicator("Twitter", null); 
    Intent secondIntent= new Intent(this, WebViewActivity2.class); 
    secondSpec.setContent(secondIntent); 
    th.addTab(secondSpec); 

    TabSpec thirdSpec=th.newTabSpec("Facebook"); 
    thirdSpec.setIndicator("Facebook", null); 
    Intent thirdIntent= new Intent(this, WebViewActivity3.class); 
    thirdSpec.setContent(thirdIntent); 
    th.addTab(thirdSpec); 
} 



@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 

} 

} 

web視圖代碼

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.webkit.WebView; 

public class WebViewActivity extends Activity { 

public WebView webView_A; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 



    webView_A = (WebView) findViewById(R.id.tab1); 
    webView_A.getSettings().setJavaScriptEnabled(true); 
    webView_A.loadUrl("http://www.eventbrite.com"); 

} 



@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.web_view, menu); 
    return true; 
} 

} 

的XML主要佈局

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#FFB84D" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="-3dip" 
     android:layout_weight="0" > 
    </TabWidget> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </FrameLayout> 
</LinearLayout> 

</TabHost> 

繼承人的logcat的。

1月5日至23日:23:06.886:W/dalvikvm(14673):線程ID = 1:螺紋帶 未捕獲的異常(組= 0x4160e930) 1月5日至23日在退出:23:06.910:E/AndroidRuntime (14673):致命例外:main 05-23 01:23:06.910:E/AndroidRuntime(14673):java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.company.client/com.company.client .MainActivity}: java.lang.IllegalStateException:你忘記調用'public void setup(LocalActivityManager activityGroup)'嗎? E/AndroidRuntime(14673):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 05-23 01:23:06.910:E/AndroidRuntime(14673): 05-23 01:23:06.910:在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.app.ActivityThread.access $ 600(ActivityThread.java:153) 05 -23 01:23:06.910:E/AndroidRuntime(14673):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1247) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.os.Handler.dispatchMessage(Handler.java:99) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.os.Looper.loop(Looper.java:137) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.app.ActivityThread.main(A E/AndroidRuntime(14673):at java.lang.reflect.Method.invokeNative(Native Method) 05-23 01:23:06.910:E/AndroidRuntime (14673):at java.lang.reflect.Method.invoke(Method.java:511) 05-23 01:23:06.910:E/AndroidRuntime(14673):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller .run(ZygoteInit.java:795) 05-23 01:23:06.910:E/AndroidRuntime(14673):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 05-23 01 :23:06.910:E/AndroidRuntime(14673):在dalvik.system.NativeStart.main(本地方法) 05-23 01:23:06.910:E/AndroidRuntime(14673):引起:java.lang.IllegalStateException:你忘了打電話給'public void setup(LocalActivityManager activityGroup)'嗎? 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.widget.TabHost $ IntentContentStrategy.getContentView(TabHost。java/747) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.widget.TabHost.setCurrentTab(TabHost.java:413) 05-23 01:23:06.910:E/AndroidRuntime 14673):at android.widget.TabHost.addTab(TabHost.java:240) 05-23 01:23:06.910:E/AndroidRuntime(14673):at com.company.client.MainActivity.onCreate(MainActivity.java: 28) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.app.Activity.performCreate(Activity.java:5104) 05-23 01:23:06.910:E/AndroidRuntime(14673) :at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 05-23 01:23:06.910:E/AndroidRuntime(14673):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261) 05 -23 01:23:06.910:E/AndroidRuntime(14673):... 11更多

那麼,我怎樣才能得到我的WebViewActivities活性在標籤中,並做什麼logcat告訴我?

回答

0

的製表活性背後的基本概念如下

TabHost爲窗口視圖中的容器。 此對象包含兩個子項:用戶單擊以選擇特定選項卡的一組選項卡標籤,以及顯示該頁面內容的FrameLayout對象。

各個元件都採用這種容器對象,而不是設置在子元件本身值通常控制。

TabWidget顯示錶示父級標籤集合中每個頁面的標籤標籤列表。這個小部件的容器對象是TabHost。 當用戶選擇一個選項卡時,該對象向容器TabHost發送一條消息,告訴切換顯示頁面。容器TabHost用於添加標籤,添加回調處理程序並管理回調。

所以調整佈局如下 -

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </FrameLayout> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="-3dip" 
     android:layout_weight="0" > 
    </TabWidget> 
    </LinearLayout> 

    </TabHost> 

和代碼片斷如下 -

tabSpec = tabHost.newTabSpec("InstructionId"); 
          tabSpec.setIndicator("INSTRUCTIONS",getResources().getDrawable(R.drawable.manual)); 
    intent = new Intent(this, InstructionsScreen.class); 
    intent.putExtra("backswipe", false); 

    tabSpec.setContent(intent); // set content must required the first before adding the tab 
    tabHost.addTab(tabSpec); 
0

第一個錯誤,我注意到的是,你想添加標籤後設置內容:

TabSpec firstSpec=th.newTabSpec("Classes & Events"); 
    firstSpec.setIndicator("Classes & Events", null); 
    Intent firstIntent= new Intent(this, WebViewActivity.class); 
    th.addTab(firstSpec); 
    firstSpec.setContent(firstIntent); 

它應該是:

TabSpec firstSpec=th.newTabSpec("Classes & Events"); 
    firstSpec.setIndicator("Classes & Events", null); 
    Intent firstIntent= new Intent(this, WebViewActivity.class); 
    firstSpec.setContent(firstIntent); 
    th.addTab(firstSpec); 
0

我認爲你需要做的是

TabSpec firstSpec=th.newTabSpec("Classes & Events"); 
firstSpec.setIndicator("Classes & Events", null); 
Intent firstIntent= new Intent(this, WebViewActivity.class); 
firstSpec.setContent(firstIntent); 
th.addTab(firstSpec); 



TabSpec secondSpec=th.newTabSpec("Twitter"); 
secondSpec.setIndicator("Twitter", null); 
Intent secondIntent= new Intent(this, WebViewActivity2.class); 
secondSpec.setContent(secondIntent); 
th.addTab(secondSpec); 



TabSpec thirdSpec=th.newTabSpec("Facebook"); 
thirdSpec.setIndicator("Facebook", null); 
Intent thirdIntent= new Intent(this, WebViewActivity3.class); 
thirdSpec.setContent(thirdIntent); 
th.addTab(thirdSpec); 

因爲你需要添加里面的TabBar標籤之前設置的內容視圖。

希望這將幫助你......

編碼快樂:)

0

logcat的告訴你,你做了正確的初始化tabhost。你應該使用'void setup(LocalActivityManager activityGroup)'。

相關問題