-2

my webview show blank page

this is my Activity Class.

class AboutFragment : BaseGreenHCMFragment() { 
    override val layoutId = R.layout.fragment_about
    override fun setupData() {}
    override fun setupView() { 
        val mWebView: WebView? = view?.findViewById(R.id.webviewdaum) as WebView
        mWebView?.loadUrl("greenhcm.com/") 
        val webSettings = mWebView?.getSettings()
        webSettings?.setJavaScriptEnabled(true) 
        // Force links and redirects to open in the WebView instead of in a browser 
        //mWebView?.setWebViewClient(WebViewClient())
    }
}

this is my xml & fragment

S T
  • 1,068
  • 2
  • 8
  • 16
  • please write your code as text not image. – S T Oct 27 '20 at 02:44
  • class AboutFragment : BaseGreenHCMFragment() { override val layoutId = R.layout.fragment_about override fun setupData() {} override fun setupView() { val mWebView: WebView? = view?.findViewById(R.id.webviewdaum) as WebView mWebView?.loadUrl("https://www.greenhcm.com/") val webSettings = mWebView?.getSettings() webSettings?.setJavaScriptEnabled(true) // Force links and redirects to open in the WebView instead of in a browser //mWebView?.setWebViewClient(WebViewClient()) } } – Iqbal Alhadad Oct 27 '20 at 02:48
  • this is my fragment sir – Iqbal Alhadad Oct 27 '20 at 02:48
  • I edit your question and make same your xml file as class code – S T Oct 27 '20 at 03:01

1 Answers1

0

anyway check this code.

class MainActivity : AppCompatActivity() {
   var mywebview: WebView? = null
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       setContentView(R.layout.activity_main)
       mywebview = findViewById<WebView>(R.id.webview)
       mywebview!!.webViewClient = object : WebViewClient() {
           override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
               view?.loadUrl(url)
               return true
           }
       }
       mywebview!!.loadUrl("https://www.google.co.in/")
   }

}

you need WebViewClient in your code.

S T
  • 1,068
  • 2
  • 8
  • 16
  • i am in fragment sir , can you help me ?, i am newbie in kotlin – Iqbal Alhadad Oct 27 '20 at 03:13
  • val mywebview: WebView = view?.findViewById(R.id.webviewdaum) as WebView mywebview!!.webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { view?.loadUrl(url) return true } } mywebview!!.loadUrl("https://www.google.co.id/") – Iqbal Alhadad Oct 27 '20 at 03:28
  • did you check internet permission? and can you write log? – S T Oct 27 '20 at 04:02
  • and where is your onCreateView in fragment lifeCycle? – S T Oct 27 '20 at 04:05
  • 2020-10-27 11:59:27.490 22171-22171/com.greenhcm.android W/ContentCatcher: Failed to notify a WebView – Iqbal Alhadad Oct 27 '20 at 04:59
  • this is my full source code inside setupview() in fragment – Iqbal Alhadad Oct 27 '20 at 05:03
  • override fun setupView() { val mywebview: WebView = view?.findViewById(R.id.webviewdaum) as WebView mywebview!!.webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { view?.loadUrl(url) return true } } //errror in this mywebview!!.loadUrl("https://www.google.co.id/") } – Iqbal Alhadad Oct 27 '20 at 05:23
  • pleae help me sir – Iqbal Alhadad Oct 27 '20 at 05:24
  • D/EgretLoader: The context is not activity – Iqbal Alhadad Oct 27 '20 at 05:31
  • check this article https://stackoverflow.com/a/47322914/10778405. and just change code to Kotlin – S T Oct 27 '20 at 07:53