0

Android WebView I need links to open within WebView without using the default browser. I have tried a million things.i can get it to work with a normal webview however with this im not sure how to go about it

package com.subspace.dev;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.*;

import com.subspace.dev.dummy.DummyContent;

/**
 \* A fragment representing a single Site detail screen. This fragment is either
 * contained in a {@link SiteListActivity} in two-pane mode (on tablets) or a
 * {@link SiteDetailActivity} on handsets.
 */
  public class SiteDetailFragment extends Fragment {
/**
 * The fragment argument representing the item ID that this fragment
 * represents.
 */
public static final String ARG_ITEM_ID = "item_id";

/**
 * The dummy content this fragment is presenting.
 */
private DummyContent.DummyItem mItem;

/**
 * Mandatory empty constructor for the fragment manager to instantiate the
 * fragment (e.g. upon screen orientation changes).
 */
public SiteDetailFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getArguments().containsKey(ARG_ITEM_ID)) {
        // Load the dummy content specified by the fragment
        // arguments. In a real-world scenario, use a Loader
        // to load content from a content provider.
        mItem = DummyContent.ITEM_MAP.get(getArguments().getString(
                ARG_ITEM_ID));
    }
}

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_site_detail,
            container, false);

    // Show the WebView.

    if (mItem != null)
    {

        ((WebView) rootView.findViewById(R.id.site_detail))
                .loadUrl(mItem.website_url);




    }
    return rootView;
}
}

1 Answers1

0

You need to do

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

Then your WebViewClient class should look like. You might not have one so create one.

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;
    }
}

I changed the code a little from the google example found here webview example.

JCodes13
  • 488
  • 5
  • 17
  • when im calling a webview from a normal i have no problem with the above code but im working with a master detail flow template and i dont know how to inaplament that in to it – user3622469 May 11 '14 at 12:40