ポートフォリオを作成していますが、[次へ]または[nextButton](mNextButton変数)をクリックした後にロードする新しいURLに変更したいと思います。これは、Webビューが含まれているアクティビティのコードです。
package com.dredaydesigns.dredaycreativeportfolio;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.Button;
import android.R.id;
import static com.dredaydesigns.dredaycreativeportfolio.R.layout.activity_content_activity;
public class content_activity extends ActionBarActivity {
private WebView mWebView;
private Button mNextButton;
private String webURL = "http://extremesportsshows.com/"
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_content_activity);
String backgroundColor = getIntent().getExtras().getString("webColor");
ImageView iv = (ImageView) findViewById(R.id.subBanner);
iv.setBackgroundColor(Color.parseColor(backgroundColor));
mWebView = (WebView) findViewById(R.id.webView);
mWebView.loadUrl("webURL");
mNextButton= (Button) findViewById(R.id.nextButton);
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
webURL = "http://www.betterup.co/";
}
});
}
これがactivity_content_activityのxmlコードです
'
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#0e6fa2">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pageBanner"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/webactivityheader02"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/subBanner"
android:layout_below="@+id/pageBanner"
android:layout_alignLeft="@+id/pageBanner"
android:layout_alignStart="@+id/pageBanner"
android:adjustViewBounds="false"
android:padding="8dp"
android:background="#C41E72"/>
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_below="@+id/subBanner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="87dp"
android:focusableInTouchMode="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Website done for an agency that representse extreme sports athletes. Video overlay, HTML 5, JOOMLA"
android:id="@+id/contentTextView"
android:layout_marginBottom="24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEXT"
android:id="@+id/nextButton"
android:layout_above="@+id/contentTextView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>'
まず、次の行があるため、WebViewはWebページをまったくロードしません。
mWebView.loadUrl("webURL");
間違っている。StringオブジェクトをloadUrl()メソッドに渡すことになっています。その文字列は、ロードするURLである必要があります。あなたの場合、そのhttp://extremesportsshows.com/はwebURL
文字列に保存されています。したがって、コードは次のようになります。
mWebView.loadUrl(webURL); // Without the quotes
そして、[次へ]をクリックした後、次のようにWebViewにURLを再度ロードすることになっています。
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
webURL = "http://www.betterup.co/";
mWebView.loadUrl(webURL);
}
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加