你能告诉我如何做一个看起来像可以扩展的列表项的微调器吗?
我需要一些如图所示的东西。单击箭头图像时,弹出器将弹出,文本将隐藏。
我使用以下代码。
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) {
}
});
但是,箭头背景图像上方的文字也会闪烁一秒钟。
有什么建议可以避免这种情况吗?
答案 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);