我正在使用actionbarsherlock制作滑动标签,但是会出现一些错误

时间:2013-07-04 04:22:45

标签: java android actionbarsherlock

如何解决这些错误我没有得到解决方案。这里我创建了滑动标签,因为有5个标签但是会出错。我已经在评论区写了错误,如果有人有解决方案请告诉我

package com.example.tabs; // Error The type 'android.support.v4.app.Fragment' cannot be       
resolved. It is indirectly referenced from required .class files

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;

import com.example.raybits.R;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;

public class MainActivity extends SherlockFragmentActivity { // Getting Error The hierarchy        

of the type MainActivity is inconsistent

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionbar=getSupportActionBar();
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionbar.setTitle("Tab layout");

           ActionBar.Tab Tab1=actionbar.newTab().setText("Tab1")
            .setIcon(android.R.drawable.ic_btn_speak_now);
    ActionBar.Tab Tab2=actionbar.newTab().setText("Tab 2");
    ActionBar.Tab Tab3=actionbar.newTab().setText("Tab 3");
    ActionBar.Tab Tab4=actionbar.newTab().setText("Tab 4");
    ActionBar.Tab Tab5=actionbar.newTab().setText("Tab 5");

    Fragment Frag1=new Fragment_1();
    Fragment Frag2=new Fragment_2();
    Fragment Frag3=new Fragment_3();
    Fragment Frag4=new Fragment_4();
    Fragment Frag5=new Fragment_5();

    Tab1.setTabListener(new MyTabsListener(Frag1));
    Tab1.setTabListener(new MyTabsListener(Frag2));
    Tab1.setTabListener(new MyTabsListener(Frag3));
    Tab1.setTabListener(new MyTabsListener(Frag4));
    Tab1.setTabListener(new MyTabsListener(Frag5));

    actionbar.addTab(Tab1);
    actionbar.addTab(Tab2);
    actionbar.addTab(Tab3);
    actionbar.addTab(Tab4);
    actionbar.addTab(Tab5);

}
}
class MyTabsListener implements ActionBar.TabListener{
    public Fragment fragment;

    public MyTabsListener(Fragment fragment){
        this.fragment=fragment;
    }
    @Override
    public void onTabSelected(Tab tab,FragmentTransaction ft) {
        // TODO Auto-generated method stub
        ft.replace(R.id.fragment_container, fragment);

    }
    @Override
    public void onTabUnselected(Tab tab,FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onTabReselected(Tab tab,FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

}

0 个答案:

没有答案