Android ActionBar (ActionBarCompat) Spinner Dropdown list ?

后端 未结 5 2093
无人共我
无人共我 2021-02-09 15:45

I am currently working ActionBar (ActionBarCompat) oriented project, I Need some Clarification about actionbar.

I am using spinner layout like this,

<         


        
5条回答
  •  失恋的感觉
    2021-02-09 16:41

    Try this code . In menu/main.xml :

    
    

    in Activity :

    private MenuItem mSpinnerItem1 = null;
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
    
    
        MenuInflater mi=getMenuInflater();
        mi.inflate(R.menu.main, menu);
        mSpinnerItem1 = menu.findItem( R.id.menu_spinner1);
        View view1 = mSpinnerItem1.getActionView();
        if (view1 instanceof Spinner)
        {
            final Spinner spinner = (Spinner) view1;
            spinner.setAdapter(ad1);
    
    
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
                @Override
                public void onItemSelected(AdapterView arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
    
                }
    
                @Override
                public void onNothingSelected(AdapterView arg0) {
                    // TODO Auto-generated method stub
    
                }
            });
    
        }
    
        return true;
    }
    

提交回复
热议问题