如何实现一个下拉在Android的导航行动起来吧,你已经添加了它? [英] How to implement a drop down navigation action bar in Android after you've added it?

查看:150
本文介绍了如何实现一个下拉在Android的导航行动起来吧,你已经添加了它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过遵循本指南,的http://wptrafficanalyzer.in/blog/adding-drop-down-navigation-to-action-bar-in-android/

我可以加我的下拉菜单的导航栏。单击事件和一切功能。现在,我怎么让它所以一旦一个选项被选中,其导航到不同的屏幕有自己的布局和不同的功能。

I was able to add my drop down navigation bar. The click events and everything function. Now, how do I make it so once an option is selected, it navigates to a different screen with its own layout and different functions.

任何帮助将是巨大的,在此先感谢!

Any help would be great, thanks in advance!

编辑:这是我的。我的应用程序运行约1毫秒,我可以看到一个惊鸿一瞥的Hello World,然后崩溃。我使用的是福尔摩斯的方式,如果该事项。

This is what I have. My app runs for about a millisecond, and I can see a glimpse "Hello World" and then it crashes. I'm using Sherlock by the way, if that matters.

package com.poe.statcalc;

import com.actionbarsherlock.app.SherlockActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;

public class MainActivity extends SherlockActivity {

 /** An array of strings to populate dropdown list */
String[] actions = new String[] {
    "Bookmark",
    "Subscribe",
    "Share",
    "Something"

};

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

    /** Create an array adapter to populate dropdownlist */
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), R.layout.sherlock_spinner_item, actions);

    /** Enabling dropdown list navigation for the action bar */
    getSupportActionBar().setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);

    /** Defining Navigation listener */
    ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            switch(itemPosition) {
            case 0:
                Intent i = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(i);
                break;
            case 1:
                //...
                break;
            }
            return false;
        }
    };

    /** Setting dropdown items and item navigation listener for the actionbar */
    getSupportActionBar().setListNavigationCallbacks(adapter, navigationListener);
    adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

}

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    getSupportMenuInflater().inflate(R.menu.activity_main, menu);
    return super.onCreateOptionsMenu(menu);
}

}

推荐答案

您需要maniputate你的 ArrayAdapter 如果你想改变的元素,但我不认为您可以使用 ArrayAdapter&LT;字符串&GT; 类的porouse。您可能需要使用别的东西不是字符串。

You need to maniputate your ArrayAdapter if you want to change the elements, but I don't think you you can use the ArrayAdapter<String> class for that porouse. You may need to use something else than string.

有关处理点击您需要更改 onNavigationItemSelected 功能:

For handling clicks you need to change the onNavigationItemSelected function:

@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
    switch(itemPosition) {
    case 0:
        Intent i = new Intent(this, SecondActivity.class);
        startActivity(i);
        break;
    case 1:
        // ...
        break;
    }
    return false;
}

这篇关于如何实现一个下拉在Android的导航行动起来吧,你已经添加了它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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