В настоящее время у меня установлено мое приложение с ListFragment
слева и DetailsFragment
справа (аналогично расположению на планшете ниже).WebViewFragment webView имеет значение null после выполнения FragmentTransaction
На детали фрагмента (фрагмент рядом со списком) У меня есть кнопка Гото сделки, которая при нажатии следует заменить detailsFragment с WebViewFragment
.
Проблема, с которой я столкнулась, заключается в том, что при попытке загрузить URL-адрес в веб-фрагменте просмотра WebView
имеет значение 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");
Ниже приведена моя основная компоновка, в которой определены исходные два фрагмента.
<?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>
Кажется, что webViewFragment не создается полностью как WebView
не отформатирована. Я посмотрел онлайн, но есть очень мало информации о WebViewFragment
.
Любые идеи, как обеспечить WebView
инициализируется в WebViewFragment
?
Пожалуйста, пост код для вашего класса DealWebViewFragment. – Jonathan
@ Jonathan - Извините, мой DealWebViewFragment был всего лишь воссозданием WebViewFragment. Я изменил приведенный выше код обратно в WebViewFragment (та же проблема существует). – bencallis