ブラウザアプリを作ろうとしているのですが、インターネットに繋がらないのが難点です
マルチタブなので、コードは次のとおりです。
主な活動:
public class TabTestActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost host=getTabHost();
host.addTab(host.newTabSpec("two")
.setIndicator("facebook")
.setContent(new Intent(this,facebrowser.class)));
host.addTab(host.newTabSpec("one")
.setIndicator("Google")
.setContent(new Intent(this,googlebrowser.class)));
}
}
tab1 アクティビティ:
public class facebrowser extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
WebView browse = new WebView(this);
setContentView(browse);
browse.loadUrl("http:\\www.facebook.com");
}
}
tab2 アクティビティ:
public class googlebrowser extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
WebView browse = new WebView(this);
setContentView(browse);
browse.loadUrl("http:\\www.google.com");
}
}
xml レイアウト:
<?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: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" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</TabHost>
マニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.TabBrowse"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TabTestActivity"
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="googlebrowser" android:label="name">
</activity>
<activity android:name="facebrowser" android:label="name"></activity>
</application>
</manifest>
そして、ページは私に教えてくれます:
Webページは利用できません
http://www.facebook.com の Web ページが一時的に停止しているか、新しい Web アドレスに完全に移動している可能性があります。
以下にいくつかの提案を示します。
- デバイスに信号とデータ接続があることを確認してください。
- このウェブページをあとでリロードしてください。
Google の Web ページのキャッシュ コピーを表示する