2012-11-30 30 views
0

正如我們在片段加載網頁視圖這樣的:如何使用片段在線性佈局android中加載新內容?

​​

,但我想使用線性佈局,而不是網頁流量的。 我嘗試這個,但錯誤出來。

private LinearLayout viewer ; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     viewer = (LinearLayout) inflater.inflate(R.layout.tut_view, container, false); 


     View fragment = inflater.inflate(R.layout.tut_view, null); 
     return viewer; 
    } 
    public void updateUrl(String newUrl) { 
     if (viewer != null) { 


     } 
    } 

回答

1

您應該在您的xml文件中以root身份使用LinearLayout。此外,您不需要投射充氣視圖,因爲返回類型是View。請閱讀fragment spec

+0

,但我想重新加載在片段觀活動,每次只是讓我知道什麼是這個代碼的基本檢查:如果 (!觀衆= NULL){ } –

相關問題