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); } } }); } }