Code example for Fragment

Methods: getArgumentsgetFragmentManagerisAdded

0
            // the view hierarchy; it would just never be used. 
            return null; 
        } 
 
        if (getShownIndex() >= mQuickShare.getFeed().size()) {
            if (isAdded()) getFragmentManager().beginTransaction().remove(this).commit();
            return null; 
        } 
 
        Log.d(TAG, "[onCreateView]");
 
        View v = inflater.inflate(R.layout.story_detail_webview, container, false);
 
        Button mShareStory = (Button) v.findViewById(R.id.share_button);
        mShareStory.setOnClickListener(this);
 
        mWebView = (WebView) v.findViewById(R.id.story_webview);
 
        Log.d(TAG, "[onCreateView] url: loading the current story");
 
        loadCurrentStory(); 
        return v;
    } 
 
    public void loadCurrentStory() { 
        Story story = getShownStory();
 
        String styleCommon = getResources().getString(R.string.html_style_sheet_common);
        String style = getString(R.string.html_style_sheet);
 
        int targetWidth = (int) getResources().getDimension(R.dimen.fragmentImageWidth);
        String htmlString =
                "<html>" + 
                    "<head>" + 
                        "<style type=\"text/css\">" + 
                            styleCommon +
                            style +
                        "</style>" + 
                    "</head>" + 
                    "<body>" + 
                        "<div class=\"main\">" + 
                        "<div class=\"title\">" + story.getTitle() + "</div>" +
                        "<div class=\"date\">" + story.getFormattedDate() + "</div>" +
                        "<div class=\"posted_by\">Posted by: " + story.getPostedBy() + "</div>" +
                        "<div class=\"body\">" + story.getDescriptionWithScaledImages(targetWidth) + "</div>" +
                    "</body>" + 
                "</html>"; 
 
        Log.d(TAG, "[loadCurrentStory] html: "
                + htmlString.substring(0, Math.min(50, htmlString.length())));
 
        mWebView.loadDataWithBaseURL("http://www.janrain.com/blogs/", htmlString, "text/html", "UTF-8", "");
    } 
 
    public int getShownIndex() { 
        return getArguments().getInt("index", 0);
    } 
 
    public Story getShownStory() { 
        return mQuickShare.getFeed().get(getShownIndex());
    } 
Stop searching for code, let great code find you!  Add Codota to your java IDE