How to update the Drop-down Navigation title when user selects an option?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 07:10:39

问题


I have a Drop-down Navigation (Spinner) in my Action Bar.

For creating the spinner, I used the code below, on my onCreate() method:

//SPINNER
    SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.main_options,
            android.R.layout.simple_spinner_dropdown_item);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getActionBar().setListNavigationCallbacks(mSpinnerAdapter,this);

main_options is a array in strings.xml resources, and has 3 options, which are shown on the Drop-down Navigation list (Spinner) when Activity is shown. Currently, the first option appears as "selected".

When I choose an option of the spinner list, it show an Toast message.

Current code of the method onNavigationItemSelected():

    @Override
public boolean onNavigationItemSelected(int arg0, long arg1) {
   Toast.makeText(getApplicationContext()," text",1000).show();
    return true;
}

I want to modify it to refresh the activity (for this, I will call onRestart() method), but also: I want to update the title of the Drop-down list for the current selected option.

How can I do it?

来源:https://stackoverflow.com/questions/21137497/how-to-update-the-drop-down-navigation-title-when-user-selects-an-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!