package com.basic.security.widget;
|
|
import android.content.Context;
|
import android.util.AttributeSet;
|
import android.widget.ListPopupWindow;
|
import android.widget.ListView;
|
import android.widget.Spinner;
|
|
|
import java.lang.reflect.Field;
|
|
public class CustomSpinner extends Spinner {
|
|
public CustomSpinner(Context context) {
|
this(context, null);
|
}
|
|
public CustomSpinner(Context context, AttributeSet attrs) {
|
this(context, attrs, 0);
|
}
|
|
public CustomSpinner(Context context, AttributeSet attrs, int defStyle) {
|
super(context, attrs, defStyle, 0, 1);
|
}
|
|
@Override
|
public boolean performClick() {
|
super.performClick();
|
try {
|
Field f = this.getClass().getSuperclass().getDeclaredField("mPopup");
|
f.setAccessible(true);
|
ListPopupWindow listPopupWindow = (ListPopupWindow) f.get(this);
|
listPopupWindow.setModal(false);
|
ListView listView = listPopupWindow.getListView();
|
if (listView != null) {
|
listView.setDivider(null);
|
listView.setDividerHeight(0);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return true;
|
}
|
|
public interface Selection {
|
public void selected(int position);
|
}
|
|
public Selection selection;
|
|
@Override
|
public void setSelection(int position) {
|
if (selection != null) {
|
selection.selected(position);
|
}
|
super.setSelection(position);
|
}
|
|
@Override
|
public void setSelection(int position, boolean animate) {
|
super.setSelection(position, animate);
|
}
|
}
|