2010-08-28 95 views
0

我一直在嘗試添加一個WebView在TabView中的其中一個選項卡,但它不工作。 當我去其他標籤我只是TextViews和他們工作正常,但只要我點擊與網站在它的選項卡,錯誤意外關閉。 這裏是我的search_result.java具有TabView的現在WebView內TabView失敗

package supa.mack.doppler; 

import android.app.Activity; 
import android.app.TabActivity; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TabHost; 

public class search_result extends TabActivity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.search_result); 

    TabHost mTabHost; 
    mTabHost = getTabHost(); 

    mTabHost.addTab(mTabHost.newTabSpec("Results").setIndicator("Results").setContent(R.id.textview1)); 
    mTabHost.addTab(mTabHost.newTabSpec("Location").setIndicator("Location").setContent(R.id.textview2)); 
    mTabHost.addTab(mTabHost.newTabSpec("Facebook") 
     .setIndicator("Facebook") 
     .setContent(new Intent(this, BioActivity.class))); 

    mTabHost.setCurrentTab(0); 


Button searchButton=(Button) findViewById(R.id.return_button); 
    searchButton.setOnClickListener(new View.OnClickListener(){ 
    public void onClick(View v) { 
    Intent intent=new Intent(
    search_result.this, 
    doppler_test.class 
    ); 

    startActivity(intent); 
    } 
}); 
} 
} 

這裏就是TabView的定義

<?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:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" android:layout_gravity="center_horizontal"> 
     <TableLayout 
    android:id="@+id/TableLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:gravity="center_horizontal"> 

     <Button 
     android:id="@+id/return_button" 
     android:layout_height="wrap_content" 
     android:text="Return" 
     android:layout_width="fill_parent"/> 

      <TableRow> 
      <TextView 
       android:id="@+id/textview1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="Here is the list of people in your location" /> 
      <TextView 
       android:id="@+id/textview2" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="Here you will see your exact location to bookmark it" /> 
      <TextView 
       android:id="@+id/textview3" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="Reference Facebook To Check The One You Seek" /> 
     </TableRow> 
     </TableLayout> 
    </FrameLayout> 
    </LinearLayout> 
</TabHost> 

這裏是BioActivity.java在web視圖定義的search_result.xml

package supa.mack.doppler; 

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

public class BioActivity extends Activity { 
WebView browser; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.web_view); 

    browser = (WebView) findViewById(R.id.webview); 
    browser.getSettings().setJavaScriptEnabled(true); 
    browser.loadUrl("http://www.google.com"); 
} 
} 

最後這是放置webView的web_view.xml

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

O和差點忘了加我的清單....

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="supa.mack.doppler" 
     android:versionCode="1" 
     android:versionName="1.0"> 
     <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> 
     <activity android:name=".doppler_test" 
        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=".search_result"> 
    <activity android:name=".search_result" android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar"/> 
     <activity android:name=".BioActivity" android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar"/> 
    </activity> 
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 
    <uses-permission android:name="android.permission.BLUETOOTH" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    </application> 
     <uses-sdk android:minSdkVersion="7" /> 


</manifest> 

謝謝你看在我的代碼,它是真正破壞不能夠得到這個工作,我的一天......

回答

0

我有一種感覺,你的web_view.xml格式不正確,需要一個線性佈局或相關佈局。我幾乎一個完全相同的程序工作,我web_view.xml文件看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainlayout" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 
<WebView android:id="@+id/webview" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"/> 
</RelativeLayout> 

您也可以嘗試創建通過代碼的新web視圖,而不是與XML佈局打擾。如果你打算擁有一個webview並且不需要重用該文件,那麼你可以使用它。

編輯:我剛剛測試了你的XML方法。這似乎是有效的,工作很好。但我注意到,調用BioActivity的方法可能不正確。例如,我使用這樣的東西:

intent = new Intent().setClass(this, BioActivity.class); 
mTabHost.addTab(mTabHost.newTabSpec("Facebook") 
     .setIndicator("Facebook") 
     .setContent(intent)); 

試試看,讓我們知道它是如何工作的。我也相信你的按鈕偵聽器應該在onCreate方法之外。

+0

好吧,我加你的意圖上面代碼中,仍然有同樣的錯誤...... 至於清單又該它看起來像,因爲我沒有收到來自它的幫助任何錯誤.. 感謝至今 – user433047 2010-08-29 12:59:48

+0

這似乎是一個明顯的錯誤,如果我所有的代碼與你一起工作...... 只是似乎無法弄清楚如何重新輸入它沒有得到應用程序錯誤或語法錯誤.... – user433047 2010-08-29 13:12:30

+0

您的清單現在更正確。 「使用」應該位於應用程序標記之外,並且您還有兩個重複的活動。 – 2010-08-30 05:59:57

0

您的清單也可能不正確。您的應用程序標記未關閉,您有重複的活動,並且每個活動的標籤和主題不是必需的。爲了使網絡正常工作,您還需要添加此權限:

<uses-permission android:name="android.permission.INTERNET" /> 

缺乏權限不會ofcourse導致程序崩潰,它只是不會停,以確保你已經沿着implimented清理和制止你的艙單。