Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to close the drop down list from my custom spinner?
    primarykey
    data
    text
    <p>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.</p> <p>Can someone help me?</p> <p>EDIT: here is my code</p> <p>This is the adapter class for the spinner:</p> <pre><code>public class CategoriesAdapter extends ArrayAdapter&lt;String&gt; { 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()); } }; } </code></pre> <p>And this is the code where I call the adapter class.</p> <pre><code>spnCategories = (Spinner)findViewById(R.id.vmlL_spnCategory); categoriesAdapter = new CategoriesAdapter(this, R.layout.row_spinner_categories, categoryItems, moviesAdapter, spnCategories); spnCategories.setAdapter(categoriesAdapter); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload