如何从我的自定义微调器关闭下拉列表?

时间:2012-03-24 10:48:03

标签: android spinner

我有一个带有一个TextView和两个按钮的自定义微调器(用于对ListView进行排序)。一切正常,但在onClick(从我的一个按钮)事件被调用后,下拉列表不会关闭。我找不到手动关闭它的方法。

有人可以帮助我吗?

编辑:这是我的代码

这是微调器的适配器类:

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());
        }
    };
}

这是我调用适配器类的代码。

spnCategories = (Spinner)findViewById(R.id.vmlL_spnCategory);
categoriesAdapter = new CategoriesAdapter(this, R.layout.row_spinner_categories,
        categoryItems, moviesAdapter, spnCategories);
spnCategories.setAdapter(categoriesAdapter);

0 个答案:

没有答案