Android微调器 - 展开列表视图

时间:2011-01-24 11:37:07

标签: android spinner

你能告诉我如何做一个看起来像可以扩展的列表项的微调器吗?

我需要一些如图所示的东西。单击箭头图像时,弹出器将弹出,文本将隐藏。

enter image description here

我使用以下代码。

spin.setOnItemSelectedListener(new OnItemSelectedListener() {  
        public void onItemSelected(AdapterView parent, View view, int position, long id) {  
            // hide selection text  
             ((TextView)view).setText(null);  
            // if you want you can change background here  
        }  
        public void onNothingSelected(AdapterView parent) {

        }  

      });

但是,箭头背景图像上方的文字也会闪烁一秒钟。

有什么建议可以避免这种情况吗?

2 个答案:

答案 0 :(得分:1)

您可以在Array中创建要显示的Spinner项目,并从ArrayAdapter创建Array并将此ArrayAdapter设置为您的Spinner String[] items = new String[] {"One", "Two", "Three", "Four", "Five"}; Spinner spinner = (Spinner) findViewById(R.id.Spinner01);// id of your Spinner ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, items); spinner.setAdapter(adapter);

您可以尝试以下代码段:

{{1}}

参考此文件:

http://developer.android.com/resources/tutorials/views/hello-spinner.html

答案 1 :(得分:1)

试试这个

String[] androidBooks = 
    {
    "Hello, Android - Ed Burnette",
    "Professional Android 2 App Dev - Reto Meier",
    "Unlocking Android - Frank Ableson",
    "Android App Development - Blake Meike",
    "Pro Android 2 - Dave MacLean",
    "Beginning Android 2 - Mark Murphy",
    "Android Programming Tutorials - Mark Murphy",
    "Android Wireless App Development - Lauren Darcey",
    "Pro Android Games - Vladimir Silva",
    };



Spinner s=(Spinner)findViewById(R.id.Spinner01);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice,androidBooks);
  s.setAdapter(adapter);