gpt4 book ai didi

android - 在 Spinner 中单击多个下拉列表项

转载 作者:行者123 更新时间:2023-11-29 21:03:07 25 4
gpt4 key购买 nike

当您在下拉微调器的列表微调器中单击所选项目时,不要调用 onItemSelected 方法。我需要点击多个微调器的项目,所以我尝试创建自己的微调器。请帮我做这件事。也许我需要 @Override AdapterView 中的某些方法或其他东西。

最佳答案

试试这个

import android.content.Context;
import android.widget.Spinner;

public class MySpinner extends Spinner {

public MySpinner(Context context) {
super(context);
}

@Override
public void setSelection(int position, boolean animate) {
boolean sameSelected = position == getSelectedItemPosition();
super.setSelection(position, animate);
if (sameSelected) {
// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());
}
}

@Override
public void setSelection(int position) {
boolean sameSelected = position == getSelectedItemPosition();
super.setSelection(position);
if (sameSelected) {
// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());
}
}
}

关于android - 在 Spinner 中单击多个下拉列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25403042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com