views:

15

answers:

0

Hello.

I need spinner with complicated item. Item consists from text and button. But when I add button to spinner item, I can't catch onItemSelected event. Items just not select. When I remove button from item all is Ok.

So. I try to listen onClick event on textView and make spinner.setSelection(position). All is ok. My listener onItemSelectedListener notifies on this event, but spinner dropdown list not closing=(

My questiona are:

  1. How catch onItemSelected event in spenner when spinner item has button?
  2. How close spinner dropdown list from code?

Here is code of spinner:

<Spinner
  android:id="@+id/spinner"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:drawSelectorOnTop="true"   
  android:isScrollContainer="true"
  android:clipToPadding="true"/>

Here is code of spinner dropdown item:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="horizontal">

 <TextView
   android:id="@+id/title"
   style="@style/spinner_text_item"
 />

 <ImageButton
  android:id="@+id/edit"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@android:drawable/ic_menu_edit"
        /> 
</LinearLayout>

Here is code of catch item selected event:

mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                // some actions
            }

            public void onNothingSelected(AdapterView<?> parent) {      
            }
        });