我有一个包含两个片段的xml:webview和个人资料编辑器:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/editProfileFragmentOptions"
android:name="com.tests.android.Profile"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/webViewFragment"
android:name="com.tests.android.MyWebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
名为“MyWebView”的片段是我的WebView,类MyWebView看起来像:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.generic_webview,
container, false);
webView = (WebView)view.findViewById(R.id.webview);
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webView.loadData(summary, "text/html", null);
return view;
}
当我点击显示该片段时,webview仍然一直空着......这是我用来显示片段的方法:
buttonFAQ = (Button) this.findViewById(R.id.buttonFAQ);
buttonFAQ.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ACTIVE_FRAGMENT = WEBVIEW_FRAGMENT;
showFragment(WEBVIEW_FRAGMENT, true, ServerParams.WEBVIEW_FAQ);
}
});
private void showFragment(int fragmentIndex, boolean addToBackStack, ServerParams param) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
for (int i = 0; i < fragments.length; i++) {
if (i == fragmentIndex) {
if(param != null){
WebViewFragment webViewFragment = new WebViewFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("serverParams", param);
webViewFragment.setArguments(bundle);
transaction.replace(fragments[i].getId(), webViewFragment);
} else {
transaction.show(fragments[i]);
}
} else {
transaction.hide(fragments[i]);
}
}
if (addToBackStack) {
//transaction.addToBackStack("banana");
}
transaction.commit();
displayButtons(false);
}
知道为什么我的网页视图为空/空白?