Я пытался добавить WebView внутри одной из вкладок в TabView, но он не работает.
Когда я перехожу на другие вкладки, у меня просто есть TextViews, и они работают нормально, но как только я нажимаю на вкладку с веб-страницей, ошибка неожиданно закрывается.
вот мой search_result.java, у которого есть вкладка
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);
}
});
}
}
Теперь вот search_result.xml, где определяется 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, где определен веб-вид
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");
}
}
И, наконец, это web_view.xml, в который помещается webView
<?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>
Спасибо за просмотр моего кода, он действительно разрушает мой день, когда я не смог заставить его работать ...