我正在創建android應用程序與操作欄選項卡所有的代碼,如果完美,但我有一個問題,替換方法的片段如何解決這個錯誤任何人都可以幫助我?hwo修復替換方法錯誤?
在系統顯示器:
的方法,代替(INT,片段)在類型FragmentTransaction不適用於參數(INT,片段)
StartActivity.javapackage com.devlebactionbartab;
import android.net.wifi.p2p.WifiP2pManager.ActionListener;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.drm.DrmStore.Action;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class StartActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.setTitle("Tabbed Layout");
ActionBar.Tab Frag1Tab = actionbar.newTab().setText("Fragment1");
ActionBar.Tab Frag2Tab = actionbar.newTab().setText("Fragment2");
ActionBar.Tab Frag3Tab = actionbar.newTab().setText("Fragment3");
ActionBar.Tab Frag4Tab = actionbar.newTab().setText("Fragment4");
Fragment fragment1 = new Fragment_1();
Fragment fragment2 = new Fragment_2();
Fragment fragment3 = new Fragment_3();
Fragment fragment4 = new Fragment_4();
Frag1Tab.setTabListener(new MyTabsListener(fragment1));
Frag2Tab.setTabListener(new MyTabsListener(fragment2));
Frag3Tab.setTabListener(new MyTabsListener(fragment3));
Frag4Tab.setTabListener(new MyTabsListener(fragment4));
actionbar.addTab(Frag1Tab);
actionbar.addTab(Frag2Tab);
actionbar.addTab(Frag3Tab);
actionbar.addTab(Frag4Tab);
}
class MyTabsListener implements ActionBar.TabListener{
public Fragment fragment;
//constractor
public MyTabsListener (Fragment fragment){
this.fragment = fragment;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.start, menu);
return true;
}
}
@ wtsang02我照你說的導入import ** android.support.v4.app.FragmentTransaction; **但仍然是同樣的錯誤 – LebDev
同時刪除FragmentTransaction和Fragment導入,添加v4導入,乾淨。 – wtsang02
你是什麼意思加入v4進口,乾淨??我試圖只導入android.v4.app,但它給我一個錯誤 – LebDev