0

My problem is the following : at the moment I have a spinner called "projects" that I am populating in my code, but for some reasons I need to add it a title so I just do it using my adapter :

adapter.add("Choose a project");

Now I would like to remove it (via adapter.remove, this is not a problem) when the spinner in my activity is clicked (when it's opening), but the only method i am able to find is onItemSelected, which is not what I'm looking for.

Is there such thing as a onOpenListener or onClickListener for Spinner to actually execute some code when the spinner is opened, and not only when an item is selected ??

Thank you

MByD
  • 135,866
  • 28
  • 264
  • 277
Pom12
  • 7,622
  • 5
  • 50
  • 69

2 Answers2

0

This is probably because you are trying to call it inside the listener which is probably an anonymous class. Assuming your activity's class name is MyActivity use MyActivity.this.someactivitymethod where someactivitymethod is the method that you want to execute.

MByD
  • 135,866
  • 28
  • 264
  • 277
0

Spinner inherits from AbsSpinner which in turn inherits from AdapterView, which means it inherits the setOnClickListener method from AdapterView and this can be used to perform an action on clicking the spinner.

http://developer.android.com/reference/android/widget/AdapterView.html#setOnClickListener(android.view.View.OnClickListener)

EDIT: While this is true, it throws a runtime exception. Sorry.

Marshall Davis
  • 3,337
  • 5
  • 39
  • 47