0

I design custom spinner in android. This custom spinner not click-able on version greater than 3.0 and after populate the spinner value not click-able. please can anybody find out what wrong with below code then i can change my code. following is the custom spinner image
enter image description here

my main spinner.xml

<Spinner
        android:id="@+id/projDetSpnrPhase"
        style="@style/spinner_style"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="8dp"
        android:clickable="true"
        android:paddingBottom="10dp"
        android:prompt="@string/phase" />

two style of spinner one for version >11 and other for version <11

11

<style name="spinner_style" parent="fp_wc">
    <item name="android:background">@drawable/spinner_selectors</item>
    <item name="android:layout_marginLeft">10dp</item>
    <item name="android:layout_marginRight">10dp</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:paddingLeft">8dp</item>
    <item name="android:paddingTop">5dp</item>
    <item name="android:paddingBottom">5dp</item>
    <item name="android:popupBackground">#DFFFFFFF</item>
    <item name="android:spinnerStyle">@android:style/Widget.Spinner.DropDown</item>
</style>

< 11

  <style name="spinner_style" parent="fp_wc">

            <item name="android:background">@drawable/spinner_selectors</item>
            <item name="android:layout_marginLeft">10dp</item>
            <item name="android:layout_marginRight">10dp</item>
            <item name="android:layout_marginBottom">10dp</item>
            <item name="android:paddingLeft">8dp</item>
            <item name="android:paddingTop">5dp</item>
            <item name="android:paddingBottom">5dp</item>
            <item name="android:popupBackground">#DFFFFFFF</item>

    </style>

following is the spinner listener.

    spinnerPhase.setOnItemSelectedListener((OnItemSelectedListener) 
            new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {

            ........
}

spinner_selectors.xml for selector

 <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">

      <!-- Selected -->
      <item 
            android:state_pressed="true"
            android:drawable="@drawable/spinner_selector_selected" />
      <!-- Pressed -->  
      <item 
            android:state_enabled="true"
            android:drawable="@drawable/spinner_selectors_default" />

    </selector>

spinner_selector_selected.xml for border line and spinner image at corner of spinner.

 <?xml version="1.0" encoding="utf-8"?>
<item>
    <layer-list>
        <item>
            <shape>


                <stroke android:width="2dp" android:color="@color/gray" />

                <corners android:radius="4dp" />

                <padding 
                    android:bottom="3dp" 
                    android:left="3dp" 
                    android:right="3dp" 
                    android:top="3dp" />
                <solid android:color="@color/pressed_color"/>
            </shape>

        </item>

        <item>
            <bitmap 
                android:gravity="bottom|right" 
                android:src="@drawable/spinner_ab_default_new_theme_bs" />
        </item>
    </layer-list>

4

1 回答 1

0

您的侦听器代码:

  spinnerPhase.setOnItemSelectedListener((OnItemSelectedListener) 
            new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {

            ........
}

将您的侦听器代码更改为:

 spinnerPhase.setOnItemSelectedListener(new OnItemSelectedListener() {

             @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
               ............
}

然后检查并让我知道这个问题是否解决了?

于 2013-11-13T10:49:22.470 回答