6
Tôi chọn giá trị từ spinner và khi tôi chọn lại cùng một giá trị thì không có hành động nào được thực hiện trên lần nhấp.Làm cách nào để gọi hành động trên cùng một giá trị của giá trị spinner
Tôi chọn giá trị từ spinner và khi tôi chọn lại cùng một giá trị thì không có hành động nào được thực hiện trên lần nhấp.Làm cách nào để gọi hành động trên cùng một giá trị của giá trị spinner
Sử dụng tùy chỉnh này Spinner lớp ...
/** Spinner extension that calls onItemSelected even when the selection is the same as its previous value */
public class NDSpinner extends Spinner {
public NDSpinner(Context context)
{ super(context); }
public NDSpinner(Context context, AttributeSet attrs)
{ super(context, attrs); }
public NDSpinner(Context context, AttributeSet attrs, int defStyle)
{ super(context, attrs, defStyle); }
@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());
}
}
}
theo dõi các giá trị đã chọn trước đó ... và kiểm tra xem hiện tại giá trị chọn lựa chọn là trước một – Pragnani
kiểm tra hiện chọn valu và trước đó cả hai đều giống nhau hay không. –