Note:Give "INTERNET" permission in android Manifest file.
WebViewActivity.javapackage ps.webview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class WebviewActivity extends Activity implements OnClickListener
{
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
//CREATE WEBVIEW OBJECT
WebView web;
TextView edurl;
Button btgo;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// INTIALIZE WEBVIEW OBJECT
// GIVE PERMISSION INTERNET IN ANDROIDMAINFEST FILE
web=(WebView) findViewById(R.id.webView1);
edurl=(TextView) findViewById(R.id.editTexturl);
btgo=(Button) findViewById(R.id.buttongo);
btgo.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(edurl.getText().toString().equals(""))
{
Toast.makeText(this, "Pls Enter URL...", 1).show();
}
else
{
String stringurl=edurl.getText().toString();
if(!stringurl.startsWith("http://") && !stringurl.startsWith("https://") )
stringurl="http://"+stringurl;
//ENABELING JAVA SCRIPT ON WEBVIEW
web.getSettings().setJavaScriptEnabled(true);
//LOAD URL ON WEBVIEW
web.loadUrl(stringurl);
//SETTING WEBVIEW CLIENT TO OPEN IN SAME SCREEN NOT ON NATIVE BROWSER
web.setWebViewClient(new WebViewClient());
}
}
}
i am new to android development.
ReplyDeletei am getting error.
web=(WebView) findViewById(R.id.webView1);
edurl=(TextView) findViewById(R.id.editTexturl);
btgo=(Button) findViewById(R.id.buttongo);
Error: webView cannot be resolved or is not a field
Error: editTexturl cannot be resolved or is not a field
Error: buttongo cannot be resolved or is not a field
Hi Rajkumar Arumugam,
ReplyDeleteOk this error comes because may be you have imported "android.R.*" on top lines because R is resource file for your project and also android, so it check webView1, editTexturl and buttongo in android Resource file so you have to remove that imported line so it will take R file from your project.
Remove That Line and try
Happy Coding :)
& error occured
ReplyDelete