WebViewFragment O webView é nulo depois de fazer uma FragmentTransaction
Atualmente, meu aplicativo está configurado com umListFragment
à esquerda e umDetailsFragment
à direita (semelhante ao layout no tablet abaixo
No fragmento de detalhes (fragmento ao lado da lista), tenho um botão de ir para a transação, que quando pressionado deve substituir o detailsFragment por umWebViewFragment
.
O problema que estou enfrentando é que, ao tentar carregar um URL no fragmento de visualização na web, oWebView
é nulo
WebViewFragment webViewFragment = new WebViewFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.deal_details_fragment, webViewFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
// Set the url
if (webViewFragment.getWebView()==null)
Log.d("webviewfragment", "is null");
webViewFragment.getWebView().loadUrl("http://www.google.com");
baixo está o meu layout principal, que possui os dois fragmentos originais definido
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_activity_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
android:name="com.bencallis.dealpad.DealListFragment"
android:id="@+id/deal_list_fragment"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" >
<!-- Preview: layout=@layout/deal_list_fragment -->
</fragment>
<fragment
android:name="com.bencallis.dealpad.DealDetailsFragment"
android:id="@+id/deal_details_fragment"
android:layout_weight="2"
android:layout_width="0px"
android:layout_height="match_parent" >
<!-- Preview: layout=@layout/deal_details_fragment -->
</fragment>
</LinearLayout>
Parece que o webViewFragment não está sendo criado totalmente como oWebView
não foi inicializado. Procurei on-line, mas há muito pouca informação sobre oWebViewFragment
.
Alguma idéia de como garantirWebView
é inicializado noWebViewFragment
?