【发布时间】:2016-01-17 15:12:37
【问题描述】:
我的 Spinner 有一个 OnItemSelectedListener,但是当所选项目与前一个相同时,它不会被调用。我也实现了 OnClickListener,但它不起作用。我找到了一些解决方案。但我不知道我该如何使用它。我需要捕捉用户每次点击一个项目。
JAVA 代码:
spn_filter_category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),String.valueOf(position),Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
XML 代码:
<Spinner
android:id="@+id/spn_filter_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
【问题讨论】:
-
it is not called when the selected item is the same as the previous one究竟是什么意思。 -
我想使用自定义 Spinner 类来做到这一点。我该如何实施? @meda
标签: java android listener android-spinner onitemselectedlistener