I'm 16 and trying to learn Kotlin, I'm very new. I want to create a search bar which searches both Google and can open any URL you type in. I was trying to use an if else
statement, for example:
if
the first three letters were "www." then use the string url which is equal to "https://",else
use the string start_url which is equal to "google.com/search?q=";.
I just do not know how to do that and I have tried looking for help across the internet I just couldn't.
The URLUtil.isValidUrl(url) will not work because it still only loads Google Search
I am open to any comments to try and help me further learn and improve my code, even if it is not related to my question. Point out any errors or things that could be improved in my code, I know it's not perfect, thank you!
package com.example.corie.quicklinks.mainpages
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.asynclayoutinflater.R.id.text
import android.webkit.WebChromeClient
import android.webkit.WebViewClient
import com.example.corie.quicklinks.R
import com.example.corie.quicklinks.R.string.start_url
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//------------------WEBVIEW-----------------//
webViewOne.webChromeClient = WebChromeClient()
webViewOne.isVerticalScrollBarEnabled = false
webViewOne.run{
webViewOne.loadUrl("https://" + getString(start_url))
}
goBtn.setOnClickListener{
webViewOne.loadUrl("https://www.google.com/search?q=" + editText.text.toString())
}
backBtn.setOnClickListener {
if (webViewOne.canGoBack())
webViewOne.goBack()
}
nextBtn.setOnClickListener {
if (webViewOne.canGoForward())
webViewOne.goForward()
}
//------------------WEBVIEW-----------------//
}
}