2

I have a webview set up but when I click on the item, an empty fragment shows up where the actual web item is supposed to be. I have tried loading my urls on mobile browser and they work fine. I have an internet permission in android manifest.

web view layout file

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.HomeActivity">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

webview fragment

public class WebViewDetailsFragment extends Fragment {

    private WebView detailsWebView;
    private String articleSource;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_web_view_details, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        detailsWebView = view.findViewById(R.id.webView);
        detailsWebView.getSettings().setLoadsImagesAutomatically(true);
        detailsWebView.getSettings().setJavaScriptEnabled(true);
        detailsWebView.getSettings().setUseWideViewPort(true);
        detailsWebView.getSettings().setLoadWithOverviewMode(true);
        detailsWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        // Configure the client to use when opening URLs
        detailsWebView.setWebViewClient(new WebViewClient());
        setItems();
        detailsWebView.loadUrl(articleSource);


    }

    private void setItems(){
        NewsArticle newsArticle = NewsFragment.news.get(NewsAdapter.pos);
        articleSource = "https://www.google.com";
    }
}
7
  • I just tried to run your code and it works fine. The only problem that I know was about HTTP/HTTPS but in my case both worked properly. Maybe you would be able to get solution here: link Commented Aug 9, 2019 at 21:25
  • Did www.google.com actually show up or did an empty screen show? Commented Aug 9, 2019 at 21:28
  • for me it works even without URL changes. I had problems with SSL certificate previously in other page. Commented Aug 9, 2019 at 21:29
  • which ssl certificate? what does that mean? how can i fix it in my code? Commented Aug 9, 2019 at 21:40
  • You could check the link in previous comment. It solves most number of problems with that. Otherwise I don't know how to help. Commented Aug 9, 2019 at 21:46

1 Answer 1

0

I too tried your Code. it is working fine and good.There may be a chances of issue in fragmentManager. Did you checked the view is visible or not

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.