Struggling to display a specific part of a webpage in my webview, despite trying numerous solutions.
https://i.sstatic.net/b185H.png
class ActionFragment : Fragment() {
class MyWebClient : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
view.loadUrl(url)
return true
}
override fun onPageFinished(view: WebView, url: String) {
view.loadUrl("javascript:document.getElementByClassName('fc-main-container')")
}
}
private var _binding: FragmentActionBinding? = null
private val binding get() = _binding!!
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view: View = inflater.inflate(R.layout.fragment_action, container, false)
val mWebView = view.findViewById(R.id.webpage1) as WebView
mWebView.loadUrl("https://www.webmd.com/diet/healthtool-food-calorie-counter")
val webSettings = mWebView.settings
webSettings.javaScriptEnabled = true
mWebView.webViewClient = MyWebClient()
return view
}
}
In need of assistance as I am new to android development and javaScript. This is required for a college project.