Mert Serimer Mert Serimer -4 years ago 75
Android Question

Alternative to HIGHLY FLAWED SPINNER CLASS in Android

in my current project i have dealt with spinner class which has been customized from almost every aspect possible. Thus i have gained some detailed aspects as i deal with it . So i will start with the part it shows why it is flawed.

1_There is no default listener that will be fired on pop up window/layout/dialog created-showed(layout inflated) event. There are some workarounds such as ontouch listener on spinner, then check if on touch finish happened in spinner area, then you know popup will be shown but still not reliable since you can fill popup with async task..

2_On item selected event does not fire when same index is selected again. This is really annoying since i may be updating the adapter depending on other conditions which will change current selection and list order etc... Of course there is a workaround way by creating own spinner class and adding it in xml like com.myproject.customspinner etc.....(Spinner : onItemSelected not called when selected item remains the same)

3_There is no working functional OnClickListener and OnItemLongTouchListener event for spinner.

4_Changing Spinner DropDown list divider element's attributes such as color requires more labor than changing all dropdrown and spinner' background views itself which is very absurd.

5_Spinner the name itself is very absurd =))).

So what can i use instead of Spinner? Which is best way to go?

Answer Source

You can create a custom spinner using ListPopupWindow to a TextView means when a TextView is clicked a ListPopupWindow open like spinner dropdown list and you can choose a element. If you need I will help you in that.

ListPopupWindow numberList;
TextView spDays;
ArrayList<Map<String, String>>() listTrans;

in oncreate() spDays.setonclicklistner(this);spDays.setText("Select");

in onclick(){
when spDays clicked :-;

void setNumberListSpinnerView() {

numberList= new ListPopupWindow(this);

numberList.setOnItemClickListener((new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Map map = listTrans.get(position);
        circle_name = map.get("circle_name") + "";
        circle_id = map.get("circle_id").toString();
        Log.d("Circle id:", circle_id + "");


void getListItem(){
String[] numbers = {"1","2","3","4","5","6"};
listTrans = new ArrayList<Map<String, String>>();
LinkedHashMap<String, String> tran = new LinkedHashMap<String, String>();
for (String number : numbers) {
    tran.put("numbers", number);
SimpleAdapter adapter = new SimpleAdapter(AddRetailSurvey.this, listTrans,
        new String[]{"numbers"},
        new int[]{});

Check this code and modify it according to your requirement. If you found any problem I am here to help you. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download