In my program, there are many fragments.
In the ActionBar
, I have a SearchView
, and result of the search is displayed in fragment0
.
When I go to fragment2
(that does not have Webview
), I must go back fragment0
to show results.
However, when I go back to fragment0
and call the Webview
, it is null.
What's problem and solution? Here is MainActivity (where search query is excuted):
Fragment fragment0 = new SearchScrActivity();
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.content_frame, fragment0);
ft.commit();
WebView _webview = (WebView) findViewById(R.id.webViewResult);
Here is SearchScrActivity.java
public class SearchScrActivity extends SherlockFragment {
private WebView _webView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_search_screen, container,
false);
_webView = (WebView) rootView.findViewById(R.id.webViewResult);
_webView.setBackgroundColor(0x00000000);
_webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
String meaning;
meaning = "";
_webView.loadDataWithBaseURL(null, meaning, "text/html",
"utf-8", null);
return rootView;
}
}