Obecnie mam skonfigurowaną aplikację z ListFragment
po lewej stronie i DetailsFragment
po prawej stronie (podobnie jak w układzie na tablecie poniżej).WebViewFragment webView ma wartość null po wykonaniu FragmentTransaction
na fragmencie Szczegóły (fragment obok listy) Mam przycisk deal Goto, który po naciśnięciu powinien zastąpić detailsFragment z WebViewFragment
.
Problem polega na tym, że podczas próby załadowania adresu URL w widoku podglądu strony internetowej WebView
ma wartość null.
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");
Poniżej znajduje się mój główny układ zawierający oryginalne dwa fragmenty.
<?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>
Wydaje się, że webViewFragment nie jest tworzony w pełni jako WebView
nie został zainicjowany. Sprawdziłem online, ale jest bardzo mało informacji dotyczących WebViewFragment
.
pomysłów w jaki sposób zapewnić WebView
zostaje zainicjowany w WebViewFragment
?
proszę pisać kod dla klasy DealWebViewFragment. – Jonathan
@ Jonathan - Przepraszam, że mój DealWebViewFragment był po prostu odtwarzaniem WebViewFragment. Zmieniłem powyższy kod z powrotem na WebViewFragment (ten sam problem istnieje). – bencallis