Fragment does not load

1

I have a Slide View in activity_main , when I give in the menu the fragment to load does not load follows the screen of activity_main

public class BlankFragment extends Fragment {
    WebView mWebView;

    public BlankFragment() {
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View v=inflater.inflate(R.layout.fragment_blank, container, false);
        mWebView = (WebView) v.findViewById(R.id.webView);
        mWebView.loadUrl("http://www.google.es");

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        mWebView.setInitialScale(80);

        mWebView.setWebViewClient(new WebViewClient());

        return v;
    }    
}
    
asked by jorje garcia 05.09.2016 в 07:56
source

2 answers

1

The problem might not be in the Fragment , probably the way in which loads the Fragment is the problem, this must be the correct way:

 // Crea el nuevo fragmento y la transacción.
 Fragment nuevoFragmento = new BlankFragment();
 FragmentTransaction transaction = getFragmentManager().beginTransaction();
 transaction.replace(R.id.fragment_container, nuevoFragmento);
 transaction.addToBackStack(null);

 // Commit a la transacción
 transaction.commit();
    
answered by 29.11.2016 в 21:29
0

This happens because in the onCreateView you are inflating the last layout and open flares to things, ideally you create a separate method that is called onActivityCreated and within this put what you declared in onCreateView .

Because the first thing you should do is inflate the layout with the onCreateView and in your onCreateActivity you declare:

    mWebView = (WebView) v.findViewById(R.id.webView);
    mWebView.loadUrl("http://www.google.es");

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    mWebView.setInitialScale(80);

When I get home I'll structure it better, I'm from cel.

    
answered by 14.09.2016 в 15:09