I am trying to load a webview using a search term. So, say the searchterm entered in the search box is "abcnews" it will load the url (http://server.com/something/"+searchterm+"%20something) as (http://server.com/something/abcnews/something) But suppose if the searchterm doesnt exist, say I load something like "whatever", for which http://server.com/something/whatever/something is invalid I want the page to redirect to another page within my app (say relatedsearch view). How do I go about the same? Here's my code for the same so far: In searchtermfragment:
if((searchTerm.contains(mSearchView.getText().toString().toLowerCase() + " " + mSearchView.getText().toString().toLowerCase())))){
WebViewFragment frag = WebViewFragment.newInstanceForSearch(getFragmentManager(), searchTerm, null);
frag.setSearchTerms(searchTerm);
}
else
{
RelatedSearchResultsFragment.newInstance(getFragmentManager(), searchTerm);
}
}
and in the search webview class I have:
if (environmentApi.equalsIgnoreCase(NetworkUtils.Apis.first)) {
url = "https://mobile13.com/ms.0/fwd/service/v1/?q="+SearchTerm+"%20revenue&ui.theme=novadark&userAgent=android";
}
and in the oncreateview I have set the webview.loadurl(url);
I am not sure where or how do I validate the searchterm to get the respective fragment accordingly if the searchterm is invalid( as the url doesnt switch either upon entering an invalid search term).Any clue on how to do the same?