2013-03-20 66 views
5

我有這個問題..在類型FragmentTransaction的方法Add(INT,片段,字符串)是不適用的參數(INT,片段,字符串)

The method add(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, Fragment, String) 

使用內部的下面的代碼時FragenmtActivity

getSupportFragmentManager().beginTransaction().add(com.korovyansk.android.slideout.R.id.slideout_placeholder, ((Fragment)new CommentsMenuFragment()), "menu").commit(); 

其中CommentsMenuFragment實現:

public class CommentsMenuFragment extends Fragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.fragment_comment, container, false); 
     ListView lvComments = (ListView) view.findViewById(R.id.lvComments); 



     return view; 
    } 

} 
+4

你使用android.support.v4.app.Fragment還是android.app.Fragment? – 2013-03-20 07:37:47

+0

謝謝我在下面的問題中找到了它的答案http://stackoverflow.com/questions/11753921/error-in-fragment – Adham 2013-03-20 07:41:12

回答

29

CHEC k如果您的CommentsMenuFragment從android.support.v4.app.Fragment擴展而不是android.app.Fragment。

+1

它幫助我,我的片段被導入android.app.fragment,我改變了導入到android.support.v4.app,並添加我的FragmentActivity消失的錯誤。謝謝@PaNaVTEC – 2014-06-04 07:44:02

相關問題