1

ブラウザアプリを作ろうとしているのですが、インターネットに繋がらないのが難点です

マルチタブなので、コードは次のとおりです。

主な活動:

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 ページのキャッシュ コピーを表示する

4

2 に答える 2

1

browse.loadUrl("http:\\www.facebook.com"); の代わりに browse.loadUrl("http://www.facebook.com"); を使用します。

それはうまくいくはずです

2番目の問題について:webviewclientを作成する必要があります

public class googlebrowser extends Activity{

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    }


    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        WebView browse = new WebView(this);
        setContentView(browse);

        browse.setWebViewClient(new HelloWebViewClient());

        browse.loadUrl("http://www.google.com");
    }
}
于 2012-06-20T19:10:44.273 に答える
0

エミュレータを使用してこれをすべてテストしていますか?インターネットに接続されていない可能性があります。これはやや一般的な問題です。トラブルシューティングに役立つかもしれない他の Stackoverflow の投稿 (http://stackoverflow.com/questions/2039964/how-to-connect-android-emulator-to-the-internet) を参照してください。

于 2012-06-20T16:58:30.997 に答える