Could you please tell me how to do a spinner that look like a list item that can be expanded?
I need something like shown in the figure given.! While clicking the arrow image the spinner pops up and the text is hide.
开发者_运维问答I use the following code.
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) {
}
});
But then also there is flashing of text above the arrow background image for a second.
Any suggestion to avoid this?
try this
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);
Yo can create an Array
of the items you want to show in Spinner
and create an ArrayAdapter
from that Array
and set this ArrayAdapter
into your Spinner
.
You can try this snippet:
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);
Refer this document:
http://developer.android.com/resources/tutorials/views/hello-spinner.html
精彩评论