Java Code Examples for android.widget.Spinner#getOnItemSelectedListener()

The following examples show how to use android.widget.Spinner#getOnItemSelectedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TGBrowserView.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void refreshCollections(boolean forceDefaults) {
	ArrayAdapter<TGSelectableItem> arrayAdapter = new ArrayAdapter<TGSelectableItem>(findActivity(), android.R.layout.simple_spinner_item, createCollectionValues());
	arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

	TGBrowserCollection selectedCollection = (forceDefaults ? TGBrowserManager.getInstance(this.findContext()).getDefaultCollection() : this.findCurrentCollection());

	TGSelectableItem selectedItem = new TGSelectableItem(selectedCollection, null);
	Integer selectedItemPosition = arrayAdapter.getPosition(selectedItem);
	
	Spinner spinner = (Spinner) this.findViewById(R.id.browser_collections);
	OnItemSelectedListener listener = spinner.getOnItemSelectedListener();
	spinner.setOnItemSelectedListener(null);
	if(!this.isSameCollection(arrayAdapter, (ArrayAdapter<TGSelectableItem>) spinner.getAdapter())) {
		spinner.setAdapter(arrayAdapter);
	}
	spinner.setOnItemSelectedListener(listener);
	if( spinner.getSelectedItemPosition() != selectedItemPosition ) {
		spinner.setSelection(selectedItemPosition, false);
	}
}
 
Example 2
Source File: ExchangeFragment.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void selectSpinnerWithoutOnSelectedEvent(final Spinner spinner, int pos) {
    final AdapterView.OnItemSelectedListener listener = spinner.getOnItemSelectedListener();
    Handler handler = new Handler();
    spinner.setOnItemSelectedListener(null);
    spinner.setSelection(pos);
    handler.post(new Runnable() {
        @Override
        public void run() {
            spinner.setOnItemSelectedListener(listener);
        }
    });
}