2011-01-10 16 views
0

私は数日間は検索していませんが、回答が見つからない場合は、おそらくお手伝いできます。eclipseのAndroidアプリ

私はEclipseでアンドロイドアプリを作成しています。それはすべてうまく動作します。

package com.test; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Toast; 

public class Main extends Activity implements OnClickListener { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

    // Add Click listeners for all buttons 
     View firstButton = findViewById(R.id.btn_rassen); 
     firstButton.setOnClickListener(this); 
     View secondButton = findViewById(R.id.button2); 
     secondButton.setOnClickListener(this); 
    } 

    // Process the button click events 
@Override 
public void onClick(View v) { 
    switch(v.getId()){ 
    case R.id.btn_rassen: 
    Intent j = new Intent(this, Webscreen.class); 
     j.putExtra(com.test.Webscreen.URL, 
     "http://www.google.com/"); 

     startActivity(j); 

    break; 

    case R.id.button2: 
    Intent k = new Intent(this, Webscreen.class); 
     k.putExtra(com.test.Webscreen.URL, 
     "http://notworkingurltotest.com"); 
     startActivity(k); 
    break; 

    } 
} 
} 

はそれがwebview.javaを呼び出したときに、今というページが現れますが、私は、レイアウトXMLページで作成されていないボタン:

この

は私のmain.javaです。誰が何故このことが分かりますか?

お手数をおかけします。このOHW

は私のwebscreen.java

package com.test; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.ProgressDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Window; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import android.widget.Toast; 

public class Webscreen extends Activity { 

    public static final String URL = ""; 
    private static final String TAG = "WebscreenClass"; 
    private WebView webview; 
    private ProgressDialog progressDialog; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.webscreen); 

     this.getIntent().getExtras(); 
     this.webview = (WebView) findViewById(R.string.webview); 


     String turl = getIntent().getStringExtra(URL); 
     Log.i(TAG, " URL = "+turl); 

    WebView webview = new WebView(this); 
    setContentView(webview); 


     final Activity activity = this;  

     webview.setWebViewClient(new WebViewClient() { 
      public boolean shouldOverrideUrlLoading(WebView view, String url) {    
       view.loadUrl(url); 
       return true; 
      } 


      public void onLoadResource (WebView view, String url) { 
       if (progressDialog == null) { 
        progressDialog = new ProgressDialog(activity); 
        progressDialog.setMessage("Bezig met laden..."); 
        progressDialog.show(); 

       } 
      } 

      public void onPageFinished(WebView view, String url) { 
       if (progressDialog.isShowing()) { 
        progressDialog.dismiss(); 
        progressDialog = null; 


       } 
      } 


      public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 



       Intent myIntent = new Intent(); 
       myIntent.setClassName("com.test", "com.test.Main"); 
       startActivity(myIntent); 

       Toast.makeText(activity, "Laden van onderdeel mislukt, probeer het later nog eens! ", Toast.LENGTH_LONG).show(); 

       progressDialog.show(); 
      } 

      }); 




     webview.loadUrl(turl); 

    } 
} 

webscreen.xmlのレイアウトです:あなたが設定して第2のWebViewを作成しているよう

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <!-- <1> --> 
    <LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <EditText android:id="@+id/url" android:layout_height="wrap_content" 
     android:layout_width="wrap_content" android:lines="1" 
     android:layout_weight="1.0" android:hint="http://" 
     android:visibility="visible" /> 

    <Button android:id="@+id/go_button" android:layout_height="wrap_content" 
     android:layout_width="wrap_content" android:text="go_button" /> 

    </LinearLayout> 

    <!-- <2> --> 
    <WebView 
     android:id="@string/webview" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 

     /> 
</LinearLayout> 
+0

もっと詳しい情報が必要だと思います。たとえば、WebScreenアクティビティ用のレイアウトXMLファイルは何ですか? – C0deAttack

+0

クイック返信C0deAttackありがとう、非常に感謝、私は私のポストにレイアウトコードを追加しました。 – Colin

+0

私がコメントアウトした場合: WebView webview = new WebView(this); setContentView(webview); ボタンとテキストバーが読み込まれましたが、ページが読み込まれなくなったので、これが役に立ちますようにしてください。 – Colin

答えて

1

が見えるように、あなたのコンテンツビュー、などR.layout.webscreenが置き換えられました。

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.webscreen); 

    this.getIntent().getExtras(); 
    this.webview = (WebView) findViewById(R.string.webview); 

    String turl = getIntent().getStringExtra(URL); 
    Log.i(TAG, " URL = "+turl); 

    **WebView webview = new WebView(this); 
    setContentView(webview);** 
..... 

編集:私はちょうどあなたのコードで何か気づいた

、読み込む行する必要があります

this.webview = (WebView) findViewById(R.string.webview); 

はAcutallyこと:

this.webview = (WebView) findViewById(R.**id**.webview); 

編集2: 私がプロジェクトを作っている間に別のことに気づいた。 webscreen.xmlに次

android:id="@string/webview" 

は次のようになります。

android:id="@+id/webview" 

編集3: そしてwebscreen.xmlに気づいた別の事:

android:layout_height="0dip" 

あなたは0の高さをよろしいです?? ;-)

+0

あなたが返信していた間に投稿しました。さて、上記の理由は、あなたがボタンを表示していない理由は、あなたがビューを置き換えているためです。残念ながら、私はWebViewの仕組みに慣れていないので、ページがロードされない理由を助けることはできません。 – C0deAttack

+0

しかし、私はそれらの行を削除する場合、それはwebviewを表示しません。どのようにこれを解決するための任意の提案?正しい方向に私を向けることができますか? – Colin

+0

私の元の答えをちょうど編集しました。それが解決策ではない場合は、ここでWebViewチュートリアルをチェックすることをお勧めします。http://developer.android.com/resources/tutorials/views/hello-webview.html – C0deAttack

関連する問題