操作栏中的下拉导航无法重新开始输入

时间:2015-08-23 14:20:11

标签: android android-actionbar

我想在android中设置微调器导航,但我在TitlenagivationAdatper和spinnerNavItem上遇到错误,因为他们都无法解析为某种类型,我也尝试清理项目,导入也无法正常工作。

 ActionBar actionBar;
 // Title navigation Spinner data
 private ArrayList<SpinnerNavItem> navSpinner;
 private TitleNavigationAdapter navAdapter; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.slides);

        actionBar = getActionBar();
        actionBar.show();           

        // Enabling Spinner dropdown navigation
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        // Spinner title navigation data
        navSpinner = new ArrayList<SpinnerNavItem>();
        navSpinner.add(new SpinnerNavItem("Local",""));
        navSpinner.add(new SpinnerNavItem("My Places",""));
        navSpinner.add(new SpinnerNavItem("Checkins",""));


        // title drop down adapter
        adapter = new TitleNavigationAdapter(getApplicationContext(), navSpinner);

        // assigning the spinner navigation     
        actionBar.setListNavigationCallbacks(adapter, this);


} 
    @Override
    public boolean onNavigationItemSelected(int arg0, long arg1) {
        // TODO Auto-generated method stub
        return false;
    }

我不知道哪里出错了。请指导我。谢谢

1 个答案:

答案 0 :(得分:1)

你应该这样做:

ActionBar actionBar;
private String[] navSpinner;
private ArrayAdapter<String> navAdapter;

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

    actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    navSpinner = {"Local", "My Places", "Checkins"};
    navAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, navSpinner);

    actionBar.setListNavigationCallbacks(navAdapter, this);
}

@Override
public boolean onNavigationItemSelected(int position, long id) {
    switch (position) {
        case 0:
            //Write your code here when item selected is "Local"
            break;
        case 1:
            //Write your code here when item selected is "My Places"
            break;
        case 2:
            //Write your code here when item selected is "Checkins"
            break;
    }
    return true;
}