2011-01-10 5 views
0

나는 수 일 동안 검색했지만 답을 찾을 수 없습니다. 아마도 도움을 줄 수 있습니다.이클립스의 Android 앱

나는 이클립스에서 안드로이드 응용 프로그램을 만들고 있는데, 모든 것이 작동한다는 것은 저를 괴롭히는 것입니다.

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 레이아웃입니다 : 당신이 설정 한 후 두 번째 웹보기를 만들고있는 것처럼

<?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

더 많은 정보가 필요하다고 생각합니다. 예를 들어 웹 화면 활동을위한 레이아웃 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 : 내가 프로젝트를 만드는 동안 다른 것을 알아 차렸다.

android:id="@+id/webview" 

편집 : 3 :

android:id="@string/webview" 

될해야 다음 webscreen.xml에 다음 그리고 또 다른 한가지는 webscreen.xml에서 발견 :

android:layout_height="0dip" 

당신이 0 높이를 하시겠습니까 ?? ;-)

+0

답장하는 동안 게시했습니다. 좋아, 그래서 위의 이유는 단추를 표시하지 않는 이유는보기를 바꾸기 때문입니다. 불행하게도 WebView의 작동 방식에 익숙하지 않아 페이지가로드되지 않는 이유를 도울 수 없습니다. – C0deAttack

+0

좋아,하지만 내가 그 라인을 제거한다면 그것은 webview를 보여주지 못한다. 이 문제를 해결하는 방법에 대한 제안? 옳은 방향으로 나를 가르쳐 주시겠습니까? – Colin

+0

그냥 내 원래 대답 editted. 그게 내가 제안 할 수있는 해결책이 아니라면 WebView 튜토리얼을 여기에서 확인하는 것입니다 : http://developer.android.com/resources/tutorials/views/hello-webview.html – C0deAttack