[問題]Fragment裏的webview按上一頁出問題

作者: purin88 (原來我是憤怒的鄉民)   2015-04-09 23:37:31
最近在做一個功能,就是A Fragment點按鈕,進入B Fragment裏面有webview
程式大概如此
public class BFragment extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.query_parking, container, false);
WebView webview = new WebView(view.getContext());
webview.loadUrl("http://www.yahoo.com.tw");
webview.setWebViewClient(new WebViewClient());
return view;
}
}
A Fragment 叫B的Fragment如下
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container,new BFragment()).commit();
執行時,load網頁是沒問題的,但是按手機的上一頁鍵,程式就crush
會產生以下的錯誤
No view found for id 0x7f080054 (com.xxxx.xxxx :id/frame_container) for
fragment AFragment
java.lang.IllegalArgumentException: No view found for id 0x7f080054
(com.xxxx.xxxx :id/frame_container) for fragment AFragment{42b74848 #0
id=0x7f080054}
再更之前有類似以下的錯誤
android.util.AndroidRuntimeException: Calling startActivity() from outside of
an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really
what you want?
但我去找解決方法都是intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
但我這個是Fragment,根本沒用到Intent
這個問題處理了很久,一直找不出解,希望能有人幫忙指點一下
謝謝各位
作者: ssccg (23)   2015-04-10 10:50:00
fragment transaction加一個addToBackStack?另外你的問題看起來還有AFragment的view沒辦法再重新產生

Links booklink

Contact Us: admin [ a t ] ucptt.com