Actualmente tengo mi aplicación configurada con un ListFragment
a la izquierda y un DetailsFragment
a la derecha (similar al diseño en la tableta a continuación).WebViewFragment webView es nulo después de hacer un FragmentTransaction
En el fragmento de datos (fragmento lado de la lista) Tengo un botón de trato Goto, que al ser presionado debe reemplazar el detailsFragment con un WebViewFragment
.
El problema que tengo es que cuando intento cargar una url en el fragmento webviewf WebView
es 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");
A continuación se muestra mi diseño principal que tiene los dos fragmentos originales definidos.
<?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: [email protected]/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: [email protected]/deal_details_fragment -->
</fragment>
</LinearLayout>
Parece que el webViewFragment no se está creando plenamente como el WebView
no se ha inicializado. He buscado en línea, pero hay muy poca información sobre el WebViewFragment
.
Alguna idea de cómo asegurar WebView
se inicializa en el WebViewFragment
?
Por favor enviar el código para su clase DealWebViewFragment. – Jonathan
@Jonathan - Lo siento, mi DealWebViewFragment fue solo una recreación de WebViewFragment. He cambiado el código anterior a WebViewFragment (existe el mismo problema). – bencallis