返回列表 發帖

Android App - 按相同spinner item 可觸發 event

spinner.setOnClickListener(new
View.OnClickListener()
{
public
void onClick(View v)
{
// Do some stuff before the user changes the selection
...

spinner.setOnItemSelectedListener(new
OnItemSelectedListener()
{
@Override
public
void onItemSelected(AdapterView<?> parent,
View view,
int pos,
long id)
{
// Do some stuff based onItemSelected

You will have to set the Click listener on the underlying view (normally a TextView with id: android.R.id.text1) of the spinner. To do so:

  • Create a custom Spinner
  • In the constructor (with attributes) create the spinner by supplying the layout android.R.layout.simple_spinner_item
  • Do a findViewById(android.R.id.text1) to get the TextView
  • Now set the onClickListener to the TextView



參考
http://stackoverflow.com/questions/4130561/triggering-locationlisteners-event-manually

http://www.mkyong.com/android/android-spinner-drop-down-list-example/ <-- worth studying


搜尋字 "android spinner fire event when same item is selected"
Bill Tang     MSN:billtang@openplatform.com.hk
Openplatform Technology Co.,Ltd. 資訊坊科技有限公司  
無線工程施工、方案設計、無線產品、天饋材料、終端設備綜合供應商
Tel: 852-27491011  Fax: 852-81483532

返回列表