2014-01-23 46 views
1

你好我一直在使用導航抽屜,當然這使用片段,一切都很正常,直到我碰到這個錯誤傳來:Android的搖籃:錯誤沒有找到合適的方法進行更換

//(Radio is the name of the class i want to replace with) 
Gradle: error: no suitable method found for replace(int,Radio) 
method FragmentTransaction.replace(int,Fragment,String) is not applicable 
(actual and formal argument lists differ in length) 
method FragmentTransaction.replace(int,Fragment) is not applicable 
(actual argument Radio cannot be converted to Fragment by method invocation conversion) 

這是我的代碼:

@Override 
public void onNavigationDrawerItemSelected(int position) { 
    // update the main content by replacing fragments 
    if (position < 6){ 
     FragmentManager fragmentManager = getSupportFragmentManager(); 
     fragmentManager.beginTransaction() 
      .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) 
      .commit(); 

     PlaceholderFragment.navNumber = position + 1; 
     PlaceholderFragment.isOnline = isOnline(); 
    } else if (position == 6){ 
     FragmentManager fragmentManager = getSupportFragmentManager(); 
     fragmentManager.beginTransaction() 
       .replace(R.id.container, TvPlaceholderFragment.newInstance(position + 1)) 
       .commit(); 

     TvPlaceholderFragment.navNumber = position + 1; 
     TvPlaceholderFragment.isOnline = isOnline(); 

    } else if (position == 7) { 
     FragmentManager fragmentManager = getSupportFragmentManager(); 
     //////////// THE ERROR IS HERE ///////////// 
     fragmentManager.beginTransaction() 
       .replace(R.id.container, Radio.newInstance(position + 1)) 
       .commit(); 

     Radio.navNumber = position + 1; 
     Radio.isOnline = isOnline(); 

    } 


} 

及其一樣的其他方法如下位置7,所以我想是必須在Radio.class所以繼承人的代碼:

@TargetApi(11) 
public class Radio extends Fragment { 
    /** 
    * The fragment argument representing the section number for this 
    * fragment. 
    */ 
    private static final String ARG_SECTION_NUMBER = "section_number"; 
    public static int navNumber = 0; 
    public static boolean isOnline = false; 
public WebView webView; 
/** 
* Returns a new instance of this fragment for the given section 
* number. 
*/ 
public static Radio newInstance(int sectionNumber) { 
    Radio Fragment = new Radio(); 
    Bundle args = new Bundle(); 
    args.putInt(ARG_SECTION_NUMBER, sectionNumber); 
    Fragment.setArguments(args); 

    return Fragment; 
} 

public Radio() { 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.new_radio_main, container, false); 

    webView = (WebView) rootView.findViewById(R.id.webView2); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.loadUrl(getString(R.string.myurl)); 
    return rootView; 
} 
@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
} 
@Override 
public void onAttach(Activity activity) { 
    super.onAttach(activity); 
    ((MainActivity) activity).onSectionAttached(
      getArguments().getInt(ARG_SECTION_NUMBER)); 
} 

我並不陌生編程只是新的片段。誰能幫我?非常感謝

回答

1

您是否將Android框架類android.app.Fragment與支持庫類android.support.v4.app.Fragment混合?或混合其他框架/支持庫類?檢查你的進口。

+0

我檢查了我的導入那裏所有android.support.v4.app.Fragment –

相關問題