I'm trying to do the following
For the user do not need to type https://
I'm trying to make, when the text of EditText
starts with www.
it will automatically insert https://
I've tried:
if (!s_url.startsWith("www.")) {
myWebView.loadUrl("http://"+s_url);
}
But without success.
What am I doing wrong?
Code:
final String s_url = editText_url.getText().toString();
final WebView myWebView = (WebView) findViewById(R.id.webview);
final EditText editText_url = (EditText) findViewById(R.id.edittext_url);
//IME Action
editText_url.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = true;
if (actionId == EditorInfo.IME_ACTION_GO) {
myWebView.loadUrl(editText_url.getText().toString());
if (!s_url.startsWith("www.")) {
myWebView.loadUrl("http://"+s_url);
}
return true;
}
return true;
}
});