Save state of edittext - android

I am making a simple app.
Here are the codes:
Main 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/goButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/layout1"
android:text="#string/go" />
<EditText
android:id="#+id/urlField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/goButton"
android:background="#drawable/layout1"
android:ems="10" android:inputType="textUri"
android:hint="#string/enter_school_name">
<requestFocus />
</EditText>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/urlField" />
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/progressBar" />
Main Java:
package com.nextgenintl.plusportals;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
private WebView webView;
private EditText urlEditText;
private ProgressBar progress;
#Override
public void onBackPressed() {
if (webView.copyBackForwardList().getCurrentIndex() > 0) {
webView.goBack();
}
else {
// Your exit alert code, or alternatively line below to finish
super.onBackPressed(); // finishes activity
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
urlEditText = (EditText) findViewById(R.id.urlField);
webView = (WebView) findViewById(R.id.webView);
webView.setWebChromeClient(new MyWebViewClient());
progress = (ProgressBar) findViewById(R.id.progressBar);
progress.setMax(100);
Button openUrl = (Button) findViewById(R.id.goButton);
openUrl.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
String url = urlEditText.getText().toString();
String urlSchool = "https://www.plusportals.com/"+url;
urlSchool = urlSchool.replace(" ", "");
if (validateUrl(url)) {
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(urlSchool);
MainActivity.this.progress.setProgress(0);
}
}
private boolean validateUrl(String url) {
return true;
}
});
}
private class MyWebViewClient extends WebChromeClient {
#Override
public void onProgressChanged(WebView view, int newProgress) {
MainActivity.this.setValue(newProgress);
super.onProgressChanged(view, newProgress);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void setValue(int progress) {
this.progress.setProgress(progress);
}
}
So, I want to save the user input - the school name, so you don't have to type it every single time. But I can't really figure it out - can you please help me??? Thanks if you post me the full java file.

You can use the following:
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("clever_title", urlEditText.getText().toString());
editor.commit();
Then when you open your app the next time you can get:
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
urlEditText.text(sp.getString("clever_title", null);

Related

I make a android browser .But it doesn't support youtube video and other video also .Only sound play when i play the video and the video is black

I make a android browser .But it doesn't support youtube video and other video also .Only sound play when i play the video and the video is black. so i need the solution of this problem .Thanks in advance .
This is my code
package com.example.ashraful.userinterface;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
public class Main2Activity extends Activity {
WebView web1;
EditText ed1;
Button bt1;
String Address;
String add;
ProgressBar pbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main2);
web1 = (WebView)findViewById(R.id.webView1);
ed1 = (EditText)findViewById(R.id.editText1);
bt1 = (Button)findViewById(R.id.button1);
pbar = (ProgressBar)findViewById(R.id.progressBar1);
pbar.setVisibility(View.GONE);
bt1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Address = "http://" + ed1.getText().toString();
WebSettings webSetting = web1.getSettings();
webSetting.setBuiltInZoomControls(true);
webSetting.setJavaScriptEnabled(true);
webSetting.setLoadsImagesAutomatically(true);
web1.setWebViewClient(new WebViewClient());
web1.loadUrl(Address);
}
});
}
public class WebViewClient extends android.webkit.WebViewClient
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
pbar.setVisibility(View.VISIBLE);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
ed1.setText(""); // clear
ed1.setText(view.getUrl());
super.onPageFinished(view, url);
pbar.setVisibility(View.GONE);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) {
web1.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onBackPressed() {
Intent myIntent = new Intent(Main2Activity.this, MainActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// clear back stack
startActivity(myIntent);
finish();
return;
}
}
And This is XML code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.ashraful.userinterface.Main2Activity">
<Button
android:id="#+id/button1"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="GO"
android:layout_width="45dp" />
<View
android:id="#+id/view12"
android:layout_width="wrap_content"
android:layout_height="3dp"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentLeft="true"
android:background="#3bbdfa" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:ems="10"
android:hint="Type Your URL Here"
android:textSize="14sp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/button1"
android:layout_toStartOf="#+id/button1" />
</RelativeLayout>

Android webview browser edit text automatically change with webview change

I make a webview in android . there is a webview and edit text and a go button . I want that when the webview change the edit text automatically change with the current url . example: when i type an url "www.google.com" i go to google if i go to youtube from google but my edit text stands as "www.google.com". but i want my edit text automaticlly change as the current webview
This is my java code
package com.example.ashraful.userinterface;
import android.app.Activity;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
public class Main2Activity extends Activity {
WebView web1;
EditText ed1;
Button bt1;
String Address;
String add;
ProgressBar pbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main2); web1 =(WebView)findViewById(R.id.webView1);
ed1 = (EditText)findViewById(R.id.editText1);
bt1 = (Button)findViewById(R.id.button1);
pbar = (ProgressBar)findViewById(R.id.progressBar1);
pbar.setVisibility(View.GONE);
bt1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Address = "http://" + ed1.getText().toString();
WebSettings webSetting = web1.getSettings();
webSetting.setBuiltInZoomControls(true);
webSetting.setJavaScriptEnabled(true);
webSetting.setLoadsImagesAutomatically(true);
web1.setWebViewClient(new WebViewClient());
web1.loadUrl(Address);
}
});
}
public class WebViewClient extends android.webkit.WebViewClient
{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
pbar.setVisibility(View.VISIBLE);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
pbar.setVisibility(View.GONE);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) {
web1.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
The this is the xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.ashraful.userinterface.Main2Activity">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="GO" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentLeft="true"
android:ems="10"
android:hint="Type Your URL Here"
android:layout_toLeftOf="#+id/button1"
android:layout_toStartOf="#+id/button1" />
<View
android:id="#+id/view12"
android:layout_width="wrap_content"
android:layout_height="3dp"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentLeft="true"
android:background="#3bbdfa" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Try to set the Edittext in onPagefinished or/and in onPageStarted method:
ed1.setText(""); // clear
ed1.setText(view.getUrl()); // Set current url

Webview back button won't go back

Please Help
When you press the Back Button to get out of the application
I tried a lot of solutions, but did not succeed
I will put you code
MainActivity
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.view.View;
public class MainActivity extends Activity{
WebView webview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://www.alrofaiy.com/");
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
setProgress(progress * 100);
}
});
webview.setWebViewClient(new InsideWebViewClient());
}
#Override
public void onBackPressed() {
super.onBackPressed();
if(webview.canGoBack()){
webview.goBack();
}
}
private class InsideWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()){
case R.id.item1:
try {
Intent abb = new Intent(Intent.ACTION_SEND);
abb.setType("text/palin");
abb.putExtra(Intent.EXTRA_SUBJECT , "APP");
String aliwi = "/n /n/n";
aliwi = aliwi + "https:// /n/n";
abb.putExtra(Intent.EXTRA_TEXT, aliwi);
startActivity(Intent.createChooser(abb,""));
}
catch (Exception o)
{o.toString();}
return true;
case R.id.item2:
Intent AAA = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:info#alrofaiy.com?subhect= "));
startActivity(AAA);
return true;
case R.id.link1:
webview.loadUrl("http://www.alrofaiy.com/login_in");
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:padding="0dp">
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/webView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:focusableInTouchMode="false"
android:padding="0dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/text_call"
android:id="#+id/textView"
android:layout_alignParentBottom="true"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/webView"
android:layout_alignEnd="#+id/webView"
android:autoLink="phone"
android:clickable="true"
android:linksClickable="false"
android:textColor="#fff"
android:background="#000"
android:paddingTop="2dp" />
</RelativeLayout>
What's the solution?
When you run the application and view the site does go out when you press the back button
#Override
public void onBackPressed() {
super.onBackPressed();
if(webview.canGoBack()){
webview.goBack();
}
}
Should be
#Override
public void onBackPressed() {
if(webview.canGoBack()){
webview.goBack();
} else {
super.onBackPressed();
}
}

Spinner Appearing But not Disappearing

I am trying to implement a progress bar, that appears when loading the page and disappears when the page is finished loading. I have added on finish parameter but it seems that it is not being recognized.
Code
package com.test;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.ParseQuery;
import com.parse.PushService;
public class MainActivity extends Activity implements OnClickListener {
private Button push;
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "onReceive invoked!", Toast.LENGTH_LONG).show();
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
setContentView(R.layout.activity_main);
PushService.setDefaultPushCallback(this, MainActivity.class);
WebView webView = (WebView) findViewById(R.id.webView1);;
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.teqez.com/xx/ ");
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setBuiltInZoomControls(false);
push = (Button)findViewById(R.id.senPushB);
push.setOnClickListener(this);
}
private class HelloWebViewClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView webview, String url){
webview.loadUrl(url);
setProgressBarIndeterminateVisibility(true);
return true;
}
#Override
public void onPageFinished(WebView webview, String url){
super.onPageFinished(webview, url);
setProgressBarIndeterminateVisibility(false);
}
}
private class Callback extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return (true);
}
}
#Override
public void onBackPressed()
{
WebView webView = (WebView) findViewById(R.id.webView1);
if(webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}
#Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
}
#Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter(MyCustomReceiver.intentAction));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public void onClick(View v) {
JSONObject obj;
try {
obj = new JSONObject();
obj.put("alert", "hello!");
obj.put("action", MyCustomReceiver.intentAction);
obj.put("customdata","My message");
ParsePush push = new ParsePush();
ParseQuery query = ParseInstallation.getQuery();
// Push the notification to Android users
query.whereEqualTo("deviceType", "android");
push.setQuery(query);
push.setData(obj);
push.sendInBackground();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Layout
<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" >
<Button
android:id="#+id/senPushB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher"
android:text="Check For Updates" />
<WebView
android:id="#+id/webView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:focusable="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
You do not invoke your custom private class
Change
webView.setWebViewClient(new WebViewClient());
to
webView.setWebViewClient(new HelloWebViewClient());

How to load WebView in the same page

I have created an edittext and a go button and a webview in single layout. When a person enters a url and clicks on go button, the webview should load the website content, Instead it is going to default browser to load website how should i slove this issue ?
This is my code
xml file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
android:layout_marginTop="50dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="#+id/etenterurl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:inputType="textUri" />
<Button
android:id="#+id/buttongo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3.0"
android:text="Go" />
</LinearLayout>
</FrameLayout>
java code :
import java.util.ArrayList;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.annotation.SuppressLint;
import android.app.Activity;
public class MainActivity extends Activity {
EditText etenter;
Button bgo;
WebView webview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etenter= (EditText)findViewById(R.id.etenterurl);
bgo =(Button)findViewById(R.id.buttongo);
webview = (WebView)findViewById(R.id.webview);
bgo.setOnClickListener(new View.OnClickListener() {
#SuppressLint("SetJavaScriptEnabled")
#Override
public void onClick(View v) {
String url=etenter.getText().toString();
if(url.trim().length()>0){
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://"+url);
}
}
});
}
}
You have to use WebViewClient
wbView.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.v("uuuurl",url);
view.loadUrl(url);
return true;
}
}
See here for example
you should use WebViewClient
webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("TAG", " ==> "+url);
view.loadUrl(url);
return true;
}
});

Categories

Resources