简体   繁体   English

在onitemclick android中设置微调器项目选择的值

[英]set spinner item selected value in onitemclick android

Hello friends i have spinner as following 你好朋友我有微调如下

在此处输入图片说明

When i click on any item click event than it should be set like following 当我单击任何项​​目单击事件时,都应将其设置如下

在此处输入图片说明

it means when i select Afghnistan at that time it should be set value as AF and rest of country value remain as it is my code is as follow 这意味着当我在那时选择阿富汗时,应将其设置为AF,其余国家/地区的值保持不变,因为这是我的代码如下

On Spinner item click 在微调器项目上,单击

mSpinnerCountry.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            mStringCountryID=mArrayListCountryDatas.get(position).getId();

            mSpinnerCountry.setPrompt(mArrayListCountryDatas.get(position).getIso_alpha()+" 
        }

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

        }
    });

When i run above code it is not set value any idea how can i make it possible ? 当我在上面的代码上运行时,没有设置任何值,我该如何实现呢?

mSpinnerCountry.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> arg0, View arg1, 
            int arg2, long arg3) {
                int mStringCountryID = s1.getSelectedItemPosition(); Toast.makeText(getBaseContext(),
                    "You have selected item : " + presidents[mStringCountryID], 
                    Toast.LENGTH_SHORT).show();
            }
            public void onNothingSelected(AdapterView<?> arg0) {
            } 
        });

Try this... variable mStringCountryID will hold your specific complete value do what ever you want to do with this value. 试试这个...变量mStringCountryID将保存您的特定完整值,无论您要对该值执行什么操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM