0

我一直在尝试在我的应用程序中使用 sherlockActionBar,但尝试在 ny ics 设备或 2.3 模拟器上运行它时出现异常。

这是 Tabs_ICS.java 代码

    package com.karriapps.tehilim;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;

public class Tabs_ICS extends SherlockActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main_ics);

        ActionBar ab = getSupportActionBar();
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.Tab mainTab = ab.newTab().setText(R.string.quick).setTabListener(new mListener(new QuickAccessIcs()));
        ab.addTab(mainTab, true);

        ActionBar.Tab booksTab = ab.newTab().setText(R.string.chap).setTabListener(new mListener(new Books_ICS()));
        ab.addTab(booksTab);

        ActionBar.Tab weekTab = ab.newTab().setText(R.string.week).setTabListener(new mListener(new Week_ICS()));
        ab.addTab(weekTab);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater in = getSupportMenuInflater();
        in.inflate(R.menu.main_menu, menu);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        startActivity(new Intent(Tabs_ICS.this, Preferences.class));

        return super.onOptionsItemSelected(item);
    }
}

class mListener implements ActionBar.TabListener
{
    private Fragment fragment;
    public mListener(Fragment fragment)
    {
        this.fragment = fragment;
    }

    @Override
    public void onTabSelected(Tab tab,
            FragmentTransaction ft) {
        ft.replace(R.id.fragment_container, fragment);
    }

    @Override
    public void onTabUnselected(Tab tab,
            FragmentTransaction ft) {

        ft.remove(fragment);
    }

    @Override
    public void onTabReselected(Tab tab,
            FragmentTransaction ft) {
    }

}

我在这里做错了什么?先感谢您

4

0 回答 0