Issue
I set a button on my main layout that should execute goBack method of webview that is set on another layout. Application crashes when setOnClickListener for backButton. What I am doing wrong? Thank you.
webView class,
public class webPush extends Activity {
WebView webview;
Button backButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webview = (WebView) findViewById(R.id.webview1);
backButton = (Button)findViewById(R.id.button1);
backButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
webview.goBack();
}
});
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("http://www.google.com");
}
from main layout,
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_weight="0.02"
android:text="Back" />
Solution
in which layout u have placed button? is it in main.xml or webview layout? if the button is in main.xml then setContentView(R.layout.main);
Answered By - sush
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.