如何添加我的飞旋的动作条? [英] How can I add my spinner to the ActionBar?

查看:122
本文介绍了如何添加我的飞旋的动作条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的微调工作的操作栏下拉列表项,但我似乎无法实现它在所有的,没有很多教程这个通过谷歌搜索后。我认为它的东西做的.setListNavigationCallbacks();的code线,我只是不知道如何从该行开始得到这个工作。

对于微调

  //设置操作栏
    动作条酒吧= getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    bar.setListNavigationCallbacks();

    微调微调=(微调)findViewById(R.id.spinner1);
    ArrayAdapter< CharSequence的>适配器= ArrayAdapter.createFromResource(这一点,R.array.tools_array_stopwatch,android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(适配器);
    spinner.setOnItemSelectedListener(本);
}

公共无效onItemSelected(适配器视图<>为arg0,查看ARG1,INT ARG2,
        长ARG3){
    // TODO自动生成方法存根
    开关(ARG2){
    情况下0:
        打破;

    情况1:
        意图倒计时=新的意图(这一点,CountdownActivity.class);
        startActivity(倒计时);
        打破;

    默认 :
        打破;
    }
}

公共无效onNothingSelected(适配器视图<>为arg0){
    // TODO自动生成方法存根

}
 

解决方案

步骤#1:摆脱你的微调

步骤#2:摆脱你的 OnItemSelectedListener

第三步:提供您的 ArrayAdapter 作为第一个参数 setListNavigationCallbacks()

第四步:提供的 ActionBar.OnNavigationListener 作为第二个参数的执行 setListNavigationCallbacks()

第五步:在 onNavigationItemSelected()回调方法,你的 ActionBar.OnNavigationListener ,做到不管它是什么你想要做的基于导航的状态(例如,执行 FragmentTransaction )。

的变化

步骤#6:重新设计你的应用程序无法启动基于此导航选择一个活动,当你尝试以上。无论是从工具栏按钮或选项菜单项开始的活性,或使用片段来替换(的一部分)的用户界面上的现有的活性。在操作栏列表和选项卡导航的不是作为开展活动。

I'm trying to get my spinner working as the Action Bar Drop Down List item, but I cant seem to implement it at all, there aren't many tutorials for this after searching through Google. I think its something to do with the .setListNavigationCallbacks(); line of code, I just have no idea how to get this working from that line onwards.

// setup action bar for spinner
    ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    bar.setListNavigationCallbacks();

    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.tools_array_stopwatch, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);
}

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    // TODO Auto-generated method stub
    switch (arg2) {
    case 0:     
        break;

    case 1:                 
        Intent countdown = new Intent(this, CountdownActivity.class);
        startActivity(countdown);                       
        break;

    default :                       
        break;
    }
}

public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

解决方案

Step #1: Get rid of your Spinner.

Step #2: Get rid of your OnItemSelectedListener.

Step #3: Provide your ArrayAdapter as the first parameter to setListNavigationCallbacks().

Step #4: Provide an implementation of ActionBar.OnNavigationListener as the second parameter to setListNavigationCallbacks().

Step #5: In the onNavigationItemSelected() callback method in your ActionBar.OnNavigationListener, do whatever it is you want to do based upon the change in the state of the navigation (e.g., execute a FragmentTransaction).

Step #6: Redesign your application to not start an activity based on this navigation selection, as you are attempting above. Either start the activity from a toolbar button or options menu item, or use fragments to replace (part of) the UI on the existing activity. List and tabs navigation in the action bar is not for launching activities.

这篇关于如何添加我的飞旋的动作条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆