Example usage for android.widget ArrayAdapter setDropDownViewResource

List of usage examples for android.widget ArrayAdapter setDropDownViewResource

Introduction

In this page you can find the example usage for android.widget ArrayAdapter setDropDownViewResource.

Prototype

public void setDropDownViewResource(@LayoutRes int resource) 

Source Link

Document

Sets the layout resource to create the drop down views.

Usage

From source file:com.teleca.jamendo.activity.RadioActivity.java

/** Called when the activity is first created. */
@SuppressWarnings("unchecked")
@Override// www  .j  av  a 2  s.c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.search);

    mRadioListView = (ListView) findViewById(R.id.SearchListView);
    mRadioAdapter = new RadioAdapter(this);
    mRadioListView.setAdapter(mRadioAdapter);
    mRadioListView.setOnItemClickListener(mRadioListListener);
    mButton = (Button) findViewById(R.id.SearchButton);
    mButton.setText(R.string.radio);
    mButton.setOnClickListener(mButtonClickListener);
    mEditText = (EditText) findViewById(R.id.SearchEditText);
    mViewFlipper = (ViewFlipper) findViewById(R.id.SearchViewFlipper);

    mSpinner = (Spinner) findViewById(R.id.SearchSpinner);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.radio_modes,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(adapter);
    mEditText.setHint(R.string.radio_hint);

    mRadioLoadingDialog = new RadioLoadingDialog(this, R.string.loading_recomended_radios,
            R.string.failed_recomended_radios);

    mRadioLoadingDialog.execute();

    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
            switch (position) {
            case 0:
                // recent
                mRadioAdapter.setList(new DatabaseImpl(RadioActivity.this).getRecentRadios(20));
                break;
            case 1:
                // recommended
                switch (mRadioLoadingDialog.getStatus()) {
                case RUNNING:
                    break;
                case FINISHED:
                    mRadioLoadingDialog = new RadioLoadingDialog(RadioActivity.this,
                            R.string.loading_recomended_radios, R.string.failed_recomended_radios);
                    mRadioLoadingDialog.execute();
                    break;
                case PENDING:
                    mRadioLoadingDialog.execute();
                    break;
                }
                break;

            default:
                break;
            }

            setupListView();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    // TODO (maybe) if recent.count > 0 set to recent
    mSpinner.setSelection(1);

    mGestureOverlayView = (GestureOverlayView) findViewById(R.id.gestures);
    mGestureOverlayView
            .addOnGesturePerformedListener(JamendoApplication.getInstance().getPlayerGestureHandler());
}

From source file:com.friedran.appengine.dashboard.gui.DashboardLoadFragment.java

private Spinner setSpinnerWithItems(LinearLayout layout, int optionsListResourceID, int spinnerResourceID) {
    Spinner spinner = (Spinner) layout.findViewById(spinnerResourceID);

    // Set options list
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mActivity, optionsListResourceID,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*from w  ww  .j  av a2  s.c om*/

    // Set listener
    spinner.setOnItemSelectedListener(this);

    return spinner;
}

From source file:ca.ualberta.cmput301.t03.inventory.AddItemView.java

/**
 * {@inheritDoc}//  ww  w  .  j  a  v  a2s  .  c om
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_item_view);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    user = PrimaryUser.getInstance();

    Thread worker = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                inventoryModel = user.getInventory();
                itemModel = new Item();
                controller = new AddItemController(findViewById(R.id.add_item_view), activity, inventoryModel,
                        itemModel);
                itemPhotoController = new ItemPhotoController(itemModel);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ServiceNotAvailableException e) {
                throw new RuntimeException("App is offline.", e);
            }
        }
    });
    worker.start();

    // Source, accessed Nov 3, 2015
    // http://developer.android.com/guide/topics/ui/controls/spinner.html#Populate
    categoriesSpinner = (Spinner) findViewById(R.id.itemCategory);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.categories_array,
            android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    categoriesSpinner.setAdapter(adapter);

    addToInventoryButton = (Button) findViewById(R.id.addItem);
    addToInventoryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            controller.addItemToInventory();
        }
    });

    Button uploadPhotosButton = (Button) findViewById(R.id.uploadPhotos);
    uploadPhotosButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onUploadPhotosButtonClicked();
        }
    });
}

From source file:de.uni_koblenz_landau.apow.EncounterDetailFragment.java

/**
 * Called by EncounterDetailTask, when loading is finished.
 */// www .  j  a va2 s . c o  m
@Override
public void onEncounterFetched(Encounter encounter, List<ListViewItem> types) {
    mEncounterDetailTask = null;

    // If result is not empty, update UI, else show error message.
    if (types != null) {
        mTypes = types;
        ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(),
                android.R.layout.simple_spinner_item, types);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mTypesView.setAdapter(adapter);

        if (encounter != null) {
            mEncounter = encounter;
            mDateView.setText(Helper.dateToLocaleString(mEncounter.getEncounterDatetime(), getActivity()));
            mTimeView.setText(Helper.dateToLocaleTimeString(mEncounter.getEncounterDatetime(), getActivity()));

            int position = -1;
            for (int i = 0; i < adapter.getCount(); i++) {
                if (adapter.getItem(i).getId() == mEncounter.getEncounterType().getEncounterTypeId()) {
                    position = i;
                    break;
                }
            }
            mTypesView.setSelection(position);
        } else {
            mEncounter = new Encounter();
            mDateView.setText(Helper.dateToLocaleString(new Date(), getActivity()));
            mTimeView.setText(Helper.dateToLocaleTimeString(new Date(), getActivity()));
        }
    } else {
        Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show();
    }
}

From source file:edu.berkeley.boinc.attach.AcctMgrFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (Logging.DEBUG)
        Log.d(Logging.TAG, "AcctMgrFragment onCreateView");
    doBindService();/*  w  w w. j ava 2  s  .c o m*/
    View v = inflater.inflate(R.layout.attach_project_acctmgr_dialog, container, false);

    urlSpinner = (Spinner) v.findViewById(R.id.url_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.acct_mgr_url_list, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    urlSpinner.setAdapter(adapter);

    nameInput = (EditText) v.findViewById(R.id.name_input);
    pwdInput = (EditText) v.findViewById(R.id.pwd_input);
    warning = (TextView) v.findViewById(R.id.warning);
    ongoingWrapper = (LinearLayout) v.findViewById(R.id.ongoing_wrapper);
    continueB = (Button) v.findViewById(R.id.continue_button);
    continueB.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (Logging.DEBUG)
                Log.d(Logging.TAG, "AcctMgrFragment continue clicked");
            if (!checkDeviceOnline())
                return;
            if (asIsBound) {

                // get user input
                String url = urlSpinner.getSelectedItem().toString();
                String name = nameInput.getText().toString();
                String pwd = pwdInput.getText().toString();

                // verify input
                int res;
                if ((res = verifyInput(url, name, pwd)) != 0) {
                    warning.setText(res);
                    warning.setVisibility(View.VISIBLE);
                    return;
                }

                // adapt layout
                continueB.setVisibility(View.GONE);
                warning.setVisibility(View.GONE);
                ongoingWrapper.setVisibility(View.VISIBLE);

                String[] params = new String[3];
                params[0] = url;
                params[1] = name;
                params[2] = pwd;
                asyncTask = new AttachProjectAsyncTask();
                asyncTask.execute(params);

            } else if (Logging.DEBUG)
                Log.d(Logging.TAG, "AcctMgrFragment service not bound, do nothing...");
        }
    });

    return v;
}

From source file:com.carver.paul.truesight.Ui.CounterPicker.CounterPickerFragment.java

private void setupRolesSpinner(LayoutInflater inflater, View inflateView) {
    Spinner spinner = (Spinner) inflateView.findViewById(R.id.spinner_counter_picker);

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(inflater.getContext(),
            R.array.roles_array, android.R.layout.simple_spinner_item);

    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);//  w w w . j  a  va 2  s  .  c  o m

    spinner.setOnItemSelectedListener(this);
}

From source file:ca.farrelltonsolar.classic.HourLogChart.java

private void setupSpinner(MenuItem item) {
    try {/*w ww.  ja  v  a2s .c  o m*/
        item.setVisible(true);
        item.setActionView(R.layout.action_chart_select);
        View view = MenuItemCompat.getActionView(item);
        if (view instanceof Spinner) {
            Spinner spinner = (Spinner) view;
            String[] itemArray = getResources().getStringArray(R.array.minute_log_chart_selection);
            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this.getActivity(),
                    android.R.layout.simple_spinner_item, itemArray); //selected item will look like a spinner set from XML
            spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerArrayAdapter);
            spinner.setSelection(MonitorApplication.chargeControllers().getCurrentChargeController()
                    .getHourLogMenuSelection(), false);
            spinner.setOnItemSelectedListener(
                    new OnItemSelectedListenerWrapper(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            chartView.clearSeries();
                            if (position < mSeries.size()) {
                                MonitorApplication.chargeControllers().getCurrentChargeController()
                                        .setHourLogMenuSelection(position);
                                chartView.addSeries(mSeries.get(position));
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {

                        }
                    }));
        }
    } catch (Exception ex) {
        Log.w(getClass().getName(), String.format("Hour Log Chart failed to load setupSpinner %s ex: %s",
                Thread.currentThread().getName(), ex));
    }
}

From source file:de.uni_koblenz_landau.apow.EncounterDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.encounter_detail_fragment, container, false);

    // Create UI references.
    mDateDialog = (DateDialogFragment) getFragmentManager().findFragmentByTag(DATE_DIALOG_ID);
    if (mDateDialog != null) {
        mDateDialog.setListener(this);
    }/*from   w w  w . jav a  2s .  c o m*/
    mTimeDialog = (TimeDialogFragment) getFragmentManager().findFragmentByTag(TIME_DIALOG_ID);
    if (mTimeDialog != null) {
        mTimeDialog.setListener(this);
    }
    mDateView = (TextView) view.findViewById(R.id.encounter_detail_date);
    mTimeView = (TextView) view.findViewById(R.id.encounter_detail_time);
    mTypesView = (Spinner) view.findViewById(R.id.encounter_detail_types);

    // Restore UI from saved instance or load data.
    if (savedInstanceState != null) {
        mEncounter = (Encounter) savedInstanceState.getSerializable(ARG_ENCOUNTER);
        if (mEncounter != null) {
            mTypes = savedInstanceState.getParcelableArrayList(ARG_TYPES);
            ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, mTypes);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mTypesView.setAdapter(adapter);
        }
    } else {
        loadEncounter();
    }

    return view;
}

From source file:de.eidottermihi.rpicheck.activity.EditRaspiActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_raspi_edit);
    // Show the Up button in the action bar.
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // init sql db
    deviceDb = new DeviceDbHelper(this);

    // read device information
    int deviceId = this.getIntent().getExtras().getInt(Constants.EXTRA_DEVICE_ID);
    deviceBean = deviceDb.read(deviceId);

    // init auth spinner
    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.auth_methods,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinnerAuth.setAdapter(adapter);/*from w w w .  ja  va 2s  .c  o  m*/
    spinnerAuth.setOnItemSelectedListener(this);
    if (deviceBean.getAuthMethod().equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[0])) {
        spinnerAuth.setSelection(0);
    } else if (deviceBean.getAuthMethod().equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[1])) {
        spinnerAuth.setSelection(1);
    } else {
        spinnerAuth.setSelection(2);
    }

    // fill fields according to data from device bean
    fillFromBean();

}

From source file:bbct.android.common.activity.BaseballCardDetails.java

private ArrayAdapter<CharSequence> populateSpinnerAdapter(int arrayId) {
    Activity activity = Objects.requireNonNull(getActivity());
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(activity, arrayId,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    return adapter;
}