Spinner不使用水平列表视图

时间:2016-08-03 08:21:51

标签: android

我是android新手。我想提前特别感谢。 问题是,我使用水平列表视图并在水平列表视图适配器中使用微调器。它显示正确,但是当我们点击微调器时,onItemSelected监听器不会被调用。

下面的代码位于适配器类中,它实现了BaseAdapter

spinerConfigurableList=(Spinner) row.findViewById(R.id.spinerConfigurableList);
spinerConfigurableList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                   // spinerConfigurableList.setSelection(position);
                    configurableSelection=position;//Problem is here,this never invoke.

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

I am following this example https://github.com/MeetMe/Android-HorizontalListView

    Xml for adapter.
     <LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/llDrop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"

            >
            <Spinner
                android:id="@+id/spinerConfigurableList"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:paddingLeft="0dp"
                android:paddingRight="0dp"
                android:prompt="@string/app_name"
                android:spinnerMode="dropdown"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_margin="1dp"
                android:theme="@style/AppThemeForSpinner"
                android:textColor="@color/font_color_black_light"
                android:textSize="@dimen/font_size_level_two"
                ></Spinner>
        </LinearLayout>

1 个答案:

答案 0 :(得分:0)

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // your code here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
    }
});

改为使用它。