要设置为选择一个的微调器的第一项

时间:2016-07-12 06:04:43

标签: android

ArrayAdapter<StringWithTag> spinnerAdapter = new ArrayAdapter<StringWithTag>(RegisterActivity.this, android.R.layout.simple_spinner_item, countryList);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinnerCountry.setAdapter(spinnerAdapter);

3 个答案:

答案 0 :(得分:1)

使用countryList元素创建Select One数组。等,

String[] countryList = new String[]{"Select One" ,"India" , "China" , "Japan"};

这可能有助于你

答案 1 :(得分:0)

添加&#34;选择一个&#34;作为列表中的第一项,即countryList

答案 2 :(得分:0)

将微调器的第一项添加为“Select One”,并在onclick监听器中设置如下所述的条件。

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (position == 0)
            {
               Toast.makeText(getApplicationContext(),"Please Select any one option",Toast.LENGTH_SHORT).show();
            }
            else if (position == 1)
            {
                // add you stuff
            }
            else {
                // add your stuff
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });