2

I have a custom spinner with one TextView and two buttons (for sorting a ListView). Everything works fine, but the drop down list doesn't get closed after the onClick (from one of my buttons) event gets called. I could not find a method to close it manually.

Can someone help me?

EDIT: here is my code

This is the adapter class for the spinner:

public class CategoriesAdapter extends ArrayAdapter<String> {
    private Activity context;
    private String[] items;
    private ViewMoviesAdapter moviesAdapter;
    private Spinner spinner;
    private TextView txtCategories;    

    public CategoriesAdapter(Activity context, int textViewResourceId, String[] items,
        ViewMoviesAdapter moviesAdapter, Spinner spinner) {
        super(context, textViewResourceId, items);
        this.context = context;
        this.items = items;
        this.moviesAdapter = moviesAdapter;
        this.spinner = spinner;
    }

    // this method gets called in getView and getDropDownView
    public View getCustomView(int position, View convertView, ViewGroup parent) {

        View view = convertView;
        if (view == null) {
            LayoutInflater vi = (LayoutInflater) context.getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.row_spinner_categories, parent, false);
        }


        txtCategories = (TextView)view.findViewById(R.id.rsc_txtCategory);
        txtCategories.setText(items[position]);

        ImageButton imbSortAscending = (ImageButton)view.findViewById(R.id.rsc_imbUp);
        ImageButton imbSortDescending = (ImageButton)view.findViewById(R.id.rsc_imbDown);

        switch(position) {
            case 0:
                imbSortAscending.setOnClickListener(onIndexAscendingClick);
                imbSortDescending.setOnClickListener(onIndexDescendingClick);
                break;
            case 1:
                imbSortAscending.setOnClickListener(onNameAscendingClick);
                imbSortDescending.setOnClickListener(onNameDescendingClick);
                break;
            case 2:
                imbSortAscending.setOnClickListener(onWatchingDateAscendingClick);
                imbSortDescending.setOnClickListener(onWatchingDateDescendingClick);
                break;
        }

        return view;
    }

    private OnClickListener onNameAscendingClick = new OnClickListener() {

        @Override
        public void onClick(View v) {
                moviesAdapter.sort(new NameAscending());
        }
    };
}

And this is the code where I call the adapter class.

spnCategories = (Spinner)findViewById(R.id.vmlL_spnCategory);
categoriesAdapter = new CategoriesAdapter(this, R.layout.row_spinner_categories,
        categoryItems, moviesAdapter, spnCategories);
spnCategories.setAdapter(categoriesAdapter);
Amer A.
  • 1,025
  • 2
  • 16
  • 22

0 Answers0