I have encountered a problem which i'm unable to solve, I googled a lot but couldn't find a solution.
I made an app using master detail/flow. This app opens a webpage whenever a category item is selected but when i click another link in the webpage it redirects to browser and opens the link in the browser. Is there a way to open all the links in the app itself? All help is much appreciated! I'm all out of ideas here. Thank you.
WebpageDetailFragment.java
public class WebpageDetailFragment extends Fragment {
public static final String ARG_ITEM_ID = "item_id";
private DummyContent.DummyItem mItem;
public WebpageDetailFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments().containsKey(ARG_ITEM_ID)) {
mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
Activity activity = this.getActivity();
CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
if (appBarLayout != null) {
appBarLayout.setTitle(mItem.item_name);
}
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.webpage_detail, container, false);
// Show the dummy content as text in a TextView.
if (mItem != null) {
((WebView) rootView.findViewById(R.id.detail_area)).loadUrl(mItem.url);
}
return rootView;
}
}
I have another Problem when I add your code the same page is load in the WebView the problem of redirecting to the browser is solved but it's not loading the required page. Here my code:-
DummyContent.java
public class DummyContent {
public static final List<DummyItem> ITEMS = new ArrayList<>();
public static final Map<String, DummyItem> ITEM_MAP = new HashMap<>();
static {
addItem(new DummyItem("1", "Home", "http://techonaclick.com/"));
addItem(new DummyItem("2", "About Us", "http://techonaclick.com/about-2/"));
addItem(new DummyItem("3", "Contact Us", "http://techonaclick.com/contact-us/"));
addItem(new DummyItem("4", "Disclaimer", "http://techonaclick.com/disclaimer/"));
addItem(new DummyItem("5", "Privacy Policy", "http://techonaclick.com/privacy-policy/"));
}
private static void addItem(DummyItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
public static class DummyItem {
public final String id;
public final String item_name;
public final String url;
public DummyItem(String id, String item_name, String url) {
this.id = id;
this.item_name = item_name;
this.url = url;
}
@Override
public String toString() {
return item_name;
}
}
}