Android create a spinner with items that have a hidden value and display some text?

后端 未结 5 1531
既然无缘
既然无缘 2020-12-10 11:06

I\'m sure this is asked plenty and i\'ve found some questions on here similar but none really got the coin dropping for me. I\'m hoping someone can help me out.

What

5条回答
  •  攒了一身酷
    2020-12-10 11:50

    you can try this

    ArrayAdapter SpinerAdapter;
             String[] arrayItems = {"Strawberry","Chocolate","Vanilla"};
             final int[] actualValues={10,20,30}; 
    
            SpinerAdapter = new ArrayAdapter(this,
                    android.R.layout.simple_spinner_dropdown_item, arrayItems);
            spinner.setAdapter(SpinerAdapter);
    
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
                @Override
                public void onItemSelected(AdapterView arg0, View arg1,
                        int arg2, long arg3) {
                    int thePrice=actualValues[ arg2];
    
                }
    
                @Override
                public void onNothingSelected(AdapterView arg0) {
                    // TODO Auto-generated method stub
    
                }
            });
    

提交回复
热议问题