Reputation: 11
I am implementing a small project in which I'm diplaying a local image in my webview (in order to use the Zooming & Panning functionality), and on a button click the Next Image will be loaded. I'm able to load the image, but on the Button click I'm unable to reload the webview with the new image.
Any suggestions will really helpful. :)
Below is my WebViewActivity.java code:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view_activity);
// Initialize all View Components
flippy = (ViewFlipper)findViewById(R.id.viewFlipper1);
WebView mWebView = (WebView) findViewById(R.id.webView);
next = (ImageButton)findViewById(R.id.next);
next.setAlpha(100);
previous = (ImageButton)findViewById(R.id.previous);
previous.setAlpha(100);
mWebView.setInitialScale(0);
WebSettings webSettings = mWebView.getSettings();
webSettings.setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/start.png");
mWebView.getSettings().setBuiltInZoomControls(true);
}
public void onClickFeature (View v)
{
int id = v.getId ();
switch (id) {
case R.id.next :
imagename = /*nextImagename*/;
mWebView.loadUrl(imagename)
flippy.showNext();
break;
case R.id.previous:
imagename = /*previousImagename*/;
mWebView.loadUrl(imagename)
flippy.showNext();
break;
default:
break;
}
}
Following is the web_view_activity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
<ImageButton
android:id="@+id/previous"
android:layout_width="59dp"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:background="@null"
android:onClick="onClickFeature"
android:src="@drawable/previous" />
<ImageButton
android:id="@+id/next"
android:layout_width="59dp"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:background="@null"
android:onClick="onClickFeature"
android:src="@drawable/next" />
Upvotes: 1
Views: 2634
Reputation: 803
next.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
WebViewActivity.this.mWebView.loadUrl("your url array");
}
});
You need to handle the url array increment and decrements manually.
Upvotes: 1
Reputation: 3893
This question can help you problem: android how to create a try it yourself editor
You can dynamicly prepare and upload data to your WebView (or set url from net)
Upvotes: 0