带有微调器的EditText

时间:2012-04-24 10:51:42

标签: android

我尝试使用调用spinner创建edittext。所有工作但onItemSelected未在微调器中调用

final String[] items = new String[] {"Item1", "Item2", "Item3"};
        final Spinner spinner = new Spinner(this);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, items);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

        spinner.setOnItemSelectedListener(new AdapterView.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

            }

        });


        city.setOnFocusChangeListener(new OnFocusChangeListener(){
            public void onFocusChange(View v, boolean hasFocus)
            {
                if (hasFocus)
                {
                    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    mgr.hideSoftInputFromWindow(city.getWindowToken(), 0);
                    spinner.performClick();
                }

            }
        });

调用微调器和选择项后没有任何反应。没有调整旋转听众的电话。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

final String[] items = new String[] {"Item1", "Item2", "Item3"};
        final Spinner spinner = new Spinner(getApplicationContext());
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
                    android.R.layout.simple_spinner_item, items);

        spinner.setAdapter(adapter);

     spinner.setOnItemClickListener(new OnItemClickListener() {

        @Override
            public void onItemClick(AdapterView<?>arg0,View v, int i, long lng) {

                                //what you want

                            }
                        });