2014-09-07 5 views
0

저는 WebView가 활동 WebViewActivity에 있고 일부 이미지 버튼이 main_activity에 있습니다. 나를 도와 줄 수 있습니까? imagebutton1을 클릭하면 WebView 등의 google.com에서 WebViewActivity가 열립니다. i imagebutton2를 클릭하면 yahoo.com 등이 열립니다. Im 새로운 프로그래밍, 그리고 인스턴트 메신저 anglophone (나의 영어 나쁜 때문에 메신저에서 체코 담당자). 어떤 도움을 주셔서 감사합니다!안드로이드 - 활동 1의 활동 2에서 webview 사용하기

주요 활동

package com.tona.arcig; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ImageButton; 
import android.widget.Toast; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     addListenerOnButton(); 

    } 

    public void addListenerOnButton() { 

     ImageButton imgbutton1 = (ImageButton) findViewById(R.id.imageButton1); 
     imgbutton1.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Toast.makeText(getApplicationContext(), "I like trains", Toast.LENGTH_LONG).show(); 
      } 
     }); 
    } 

} 

WEBVIEWACTIVITY

package com.tona.arcig; 

import android.app.Activity; 
import android.os.Bundle; 

public class WebviewActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_webview); 

    } 

} 

활동의 주요 XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:contentDescription="@string/suplovani" 
      android:src="@drawable/suplovani" /> 

     <ImageButton 
      android:id="@+id/imageButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:contentDescription="@string/rozvrh" 
      android:src="@drawable/rozvrh" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageButton 
      android:id="@+id/imageButton3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:contentDescription="@string/prihlasovani" 
      android:src="@drawable/prihlasovani" /> 

     <ImageButton 
      android:id="@+id/imageButton4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:contentDescription="@string/email" 
      android:src="@drawable/email" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageButton 
      android:id="@+id/imageButton5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:contentDescription="@string/email" 
      android:src="@drawable/moodle" /> 

     <ImageButton 
      android:id="@+id/imageButton6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:contentDescription="@string/kdm" 
      android:src="@drawable/jidelna" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <ImageButton 
      android:id="@+id/imageButton7" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/o_aplikaci" 
      android:src="@drawable/about" /> 

    </LinearLayout> 

</LinearLayout> 

활동의 웹보기의 XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

</LinearLayout> 

MANIFEST

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

</LinearLayout> 

STRINGS

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <string name="suplovani">Suplování</string> 
    <string name="rozvrh">Rozvrh hodin</string> 
    <string name="prihlasovani">Přihlašování do systému</string> 
    <string name="email">Email</string> 
    <string name="moodle">Moodle</string> 
    <string name="kdm">KDM</string> 
    <string name="o_aplikaci">O Aplikaci</string> 
    <string name="app_name">Arcig.CZ</string> 
    <string name="title_webview">Arcig.CZ</string> 

</resources> 

감사합니다.

답변

0

다음은 사용자가해야하는 기본 스켈레톤입니다. 먼저 클릭 한 단추 (예 : URL 문자열)에 따라 일부 데이터를 전달해야합니다.

다음으로 데이터를 검색하고 적절한 URL을 열어야합니다. 다음은이를 수행하는 방법입니다.

Intent openWebViewActivity = new Intent(this, WebViewActivity.class); // this is current Activity 
openWebViewActivity.putExtra("web_url", "google.com"); // openWebViewActivity.putExtra("web_url", "yahoo.com"); 
startActivity(openWebViewActivity); 

이제 새로운 활동이 적절한 의도로 열립니다. 그리고 당신은 이것으로부터 URL을 얻을 수 있습니다.

package com.tona.arcig; 
import android.app.Activity; 
import android.os.Bundle; 

public class WebviewActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_webview); 

    String urlToLoad = getIntent().getStringExtra("web_url"); 
    WebView webView = (WebView) findViewById(R.id.webview); 
    webView.loadUrl(urlToLoad); 
} 
}