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.meiste.greg.ptw.tab.QuestionsForm.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    Util.log("QuestionsForm: onCreateView");

    final String json = getArguments().getString(RACE_QUESTIONS);
    if (json == null) {
        return null;
    }/*w w w . j a  va2 s .c o m*/
    final RaceQuestions rq = RaceQuestions.fromJson(json);
    final View v = inflater.inflate(R.layout.questions_form, container, false);

    final Spinner winner = (Spinner) v.findViewById(R.id.winner);
    winner.setAdapter(new DriverAdapter(getActivity(), rq.drivers));
    winner.setOnItemSelectedListener(new WinnerSelectedListener());

    final TextView q2 = (TextView) v.findViewById(R.id.question2);
    q2.setText(getActivity().getString(R.string.questions_2, rq.q2));

    final Spinner a2 = (Spinner) v.findViewById(R.id.question2a);
    final ArrayAdapter<CharSequence> a2_adapter = new ArrayAdapter<CharSequence>(getActivity(),
            android.R.layout.simple_spinner_item, rq.a2);
    a2_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    a2.setAdapter(a2_adapter);
    a2.setOnItemSelectedListener(new A2SelectedListener());

    final TextView q3 = (TextView) v.findViewById(R.id.question3);
    q3.setText(getActivity().getString(R.string.questions_3, rq.q3));

    final Spinner a3 = (Spinner) v.findViewById(R.id.question3a);
    final ArrayAdapter<CharSequence> a3_adapter = new ArrayAdapter<CharSequence>(getActivity(),
            android.R.layout.simple_spinner_item, rq.a3);
    a3_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    a3.setAdapter(a3_adapter);
    a3.setOnItemSelectedListener(new A3SelectedListener());

    final Spinner mostlaps = (Spinner) v.findViewById(R.id.mostlaps);
    mostlaps.setAdapter(new DriverAdapter(getActivity(), rq.drivers));
    mostlaps.setOnItemSelectedListener(new MostLapsSelectedListener());

    final Spinner numleaders = (Spinner) v.findViewById(R.id.numleaders);
    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.num_leaders, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    numleaders.setAdapter(adapter);
    numleaders.setOnItemSelectedListener(new NumLeadersSelectedListener());

    final Button send = (Button) v.findViewById(R.id.send);
    send.setOnClickListener(this);

    return v;
}

From source file:com.greenapp.wavecast.MapInfographActivity.java

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(43.652527, -79.38196), 4));

    // Set up the spinner/dropdown list
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*w w  w  .  j  a  v  a  2 s .  c  o  m*/
    spinner.setOnItemSelectedListener(new SpinnerActivity());

    try {
        mLists.put(getString(R.string.police_stations),
                new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url)));
        mLists.put(getString(R.string.medicare),
                new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    }

    // Make the handler deal with the map
    // Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
    // intensity from, and the map to draw the heatmap on
    // radius, gradient and opacity not specified, so default are used
}

From source file:eu.power_switch.gui.dialog.DeveloperOptionsDialog.java

@NonNull
@Override//from w ww. ja v  a2 s  . c o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    rootView = inflater.inflate(R.layout.dialog_developer_options, null);

    geofenceApiHandler = new GeofenceApiHandler(getActivity());

    CheckBox checkBox_playStoreMode = (CheckBox) rootView.findViewById(R.id.checkBox_playStoreMode);
    checkBox_playStoreMode.setChecked(DeveloperPreferencesHandler.getPlayStoreMode());
    checkBox_playStoreMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            DeveloperPreferencesHandler.setPlayStoreMode(isChecked);
        }
    });

    Button resetShowcasesButton = (Button) rootView.findViewById(R.id.button_resetShowcases);
    resetShowcasesButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MaterialShowcaseView.resetAll(getContext());
        }
    });

    Button removeAllGeofences = (Button) rootView.findViewById(R.id.button_removeAllGeofences);
    removeAllGeofences.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            geofenceApiHandler.removeAllGeofences();
        }
    });

    Button forceUnknownExceptionDialog = (Button) rootView
            .findViewById(R.id.button_forceUnknownExceptionDialog);
    forceUnknownExceptionDialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            StatusMessageHandler.showErrorDialog(getContext(), new Exception("Unknown error during runtime!"));
        }
    });

    Button forceUnhandledException = (Button) rootView.findViewById(R.id.button_forceUnhandledException);
    forceUnhandledException.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            throw new RuntimeException("Unhandled Exception");
        }
    });

    final Spinner spinnerLanguage = (Spinner) rootView.findViewById(R.id.spinner_language);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.locales,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerLanguage.setAdapter(adapter);
    spinnerLanguage.setSelection(getIndex(spinnerLanguage, DeveloperPreferencesHandler.getLocale().toString()));
    spinnerLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String localeString = spinnerLanguage.getItemAtPosition(position).toString();
            DeveloperPreferencesHandler.setLocale(new Locale(localeString));
        }

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

    CheckBox checkBoxForceLanguage = (CheckBox) rootView.findViewById(R.id.checkBox_forceLanguage);
    checkBoxForceLanguage.setChecked(DeveloperPreferencesHandler.getForceLanguage());
    checkBoxForceLanguage.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            DeveloperPreferencesHandler.setForceLanguage(isChecked);
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(rootView);
    builder.setTitle("Developer Options");
    builder.setNeutralButton(android.R.string.ok, null);

    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false); // prevent close dialog on touch outside window
    dialog.show();

    return dialog;
}

From source file:edu.teco.context.ui.Tab1Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        // We have different layouts, and in one of them this
        // fragment's containing frame doesn't exist.  The fragment
        // may still be created from its saved state, but there is
        // no reason to try to create its view hierarchy because it
        // won't be displayed.  Note this is not needed -- we could
        // just run the code below, where we would create and return
        // the view hierarchy; it would just never be used.
        return null;
    }//from www .ja va 2s  .c  o m

    View v = inflater.inflate(R.layout.tab_frag1_layout, container, false);

    List<String> probeNames = FrameworkConfiguration.getInstance().getSupportedProbeNames();

    final Spinner spinner = (Spinner) v.findViewById(R.id.spinner_sensors);
    // Create an ArrayAdapter using the string array and a default spinner
    // layout
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),
            android.R.layout.simple_spinner_item, probeNames);
    // 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);
    // Sets the listener for the spinner to this activity.
    spinner.setOnItemSelectedListener(this);
    if (probeNames.size() > 0) {
        mProbeKey = probeNames.get(0);
    }

    final Button addButton = (Button) v.findViewById(R.id.buttonAddProbe);
    addButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            addSensorFeatureCombination(v);
        }
    });

    return v;
}

From source file:com.ze.client.projecto.dialog.ProjectorDialog.java

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

    View view = inflater.inflate(R.layout.fragment_dialog_projector, container);
    mSchemes.add("http");
    mSchemes.add("https");

    mProjectorHost = ((TextInputLayout) view.findViewById(R.id.edit_host)).getEditText();
    mPort = ((TextInputLayout) view.findViewById(R.id.edit_port)).getEditText();
    mName = ((TextInputLayout) view.findViewById(R.id.edit_name)).getEditText();
    mTypeSpinner = (Spinner) view.findViewById(R.id.type_spinner);
    mSchemeSpinner = (Spinner) view.findViewById(R.id.scheme_spinner);
    TextView dialogTitle = (TextView) view.findViewById(R.id.dialog_title);

    mProjectorTypes = ProjectorDbHelper.getProjectorTypeList(getContext());
    ArrayAdapter<ProjectorType> adapter = new ArrayAdapter<>(this.getContext(), R.layout.dropdown_type,
            mProjectorTypes);//from  w  ww.  ja  v a  2 s  . c o m
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mTypeSpinner.setAdapter(adapter);

    ArrayAdapter<String> schemeAdapter = new ArrayAdapter<>(this.getContext(), R.layout.dropdown_type,
            mSchemes);
    schemeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSchemeSpinner.setAdapter(schemeAdapter);

    if (savedInstanceState != null) {
        mProjectorHost.setText(savedInstanceState.getCharSequence(TEXT_HOST));
        mPort.setText(savedInstanceState.getCharSequence(TEXT_PORT));
        mName.setText(savedInstanceState.getCharSequence(TEXT_NAME));
        mTypeSpinner.setSelection(savedInstanceState.getInt(ITEM_TYPE));
        mSchemeSpinner.setSelection(savedInstanceState.getInt(ITEM_SCHEME));
    }

    mTypeSpinner.setOnItemSelectedListener(this);

    view.findViewById(R.id.button_ok).setOnClickListener(v -> {
        URI projectorUri = null;
        try {
            projectorUri = new URI(mSchemeSpinner.getSelectedItem().toString() + "://"
                    + mProjectorHost.getText().toString() + ":" + mPort.getText().toString());
        } catch (URISyntaxException e) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(R.string.dialog_uri_not_well_formed).setTitle(R.string.dialog_title_error)
                    .create().show();
            return;
        }
        Projector projector = new Projector(mProjectorId, mName.getText().toString(), projectorUri,
                ProjectorDbHelper.getProjectorType(getContext(), mTypeId));
        if (projector.getId() == Projector.NO_ID)
            ProjectorDbHelper.insertProjector(getContext(), projector);
        else
            ProjectorDbHelper.updateProjector(getContext(), projector);
        dismiss();
    });
    view.findViewById(R.id.button_cancel).setOnClickListener(v -> dismiss());
    if (mProjector != null) {
        mProjectorHost.setText(mProjector.getUri().getHost());
        mPort.setText(String.valueOf(mProjector.getUri().getPort()));
        mName.setText(mProjector.getName());
        mTypeSpinner.setSelection(getProjectorTypePosition(mProjector.getProjectorType().getId()));
        mSchemeSpinner.setSelection(schemeAdapter.getPosition(mProjector.getUri().getScheme()));
    } else {
        mTypeSpinner.setSelection(0);
    }
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        dialogTitle.setVisibility(View.GONE);
    }

    getDialog().setTitle(R.string.mode_projector);
    return view;
}

From source file:br.ufsc.das.gtscted.shibbauth.ShibAuthenticationActivity.java

/** Called when the activity is first created. */
@Override/*from   ww  w .j  av a2 s .co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.idp_selection);
    loginButton = (Button) findViewById(R.id.loginButton);
    backButton = (Button) findViewById(R.id.backButton);
    usernameTxt = (EditText) findViewById(R.id.usernameTxt);
    passwordTxt = (EditText) findViewById(R.id.passwordTxt);
    idpSpinner = (Spinner) findViewById(R.id.idpSpinner);

    //Configura o ArrayAdapter do spinner.
    ArrayAdapter<CharSequence> spinnerArrayAdapter;
    spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    idpSpinner.setAdapter(spinnerArrayAdapter);

    // Obtm os parmetros passados pela Activity anterior 
    // (no caso, a pgina do WAYF como uma String e o
    // nico cookie da Connection usada anteriormente)
    Bundle bundle = this.getIntent().getExtras();
    String wayfHtml = bundle.getString("html_source");
    final String wayfLocation = bundle.getString("wayf_location");
    final SerializableCookie receivedCookie = (SerializableCookie) bundle.getSerializable("cookie");

    //Obtm todos os tags de nome "option", que correspondem
    // aos IdPs, da pgina do WAYF.
    Document wayfDocument = Jsoup.parse(wayfHtml);
    idpElements = wayfDocument.select("option");

    //Popula o spinner com os nomes dos IdPs encontrados.      
    for (Element idpElement : idpElements) {
        String idpName = idpElement.text();
        spinnerArrayAdapter.add(idpName);
    }

    // Obtm o caminho para o qual deve ser passado o IdP do usurio.
    formElements = wayfDocument.select("form");
    for (Element formElement : formElements) {
        if (formElement.attr("id").equals("IdPList")) {
            wayfActionPath = formElement.attr("action");
        }
    }

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Obtm a URL correspondente ao idP selecionado no spinner.
            int selectedIdpPosition = idpSpinner.getSelectedItemPosition();
            Element selectedIdp = idpElements.get(selectedIdpPosition);
            selectedIdpUrl = selectedIdp.attr("value");

            try {
                // Obtm os campos "username" e "password" fornecidos
                // pelo usurio e necessrios para a autenticao.
                String username = usernameTxt.getText().toString();
                String password = passwordTxt.getText().toString();

                // Cria um novo objeto Connection, e adiciona o 
                // cookie passado pela Activity anterior.
                Connection connection = new Connection();
                BasicClientCookie newCookie = new BasicClientCookie(receivedCookie.getName(),
                        receivedCookie.getValue());
                newCookie.setDomain(receivedCookie.getDomain());
                connection.addCookie(newCookie);

                // Tenta realizar a autenticao no IdP selecionado. O resultado corresponde
                //  pgina para a qual o cliente  redirecionado em caso de autenticao 
                // bem-sucedida.
                String authResult = connection.authenticate(wayfLocation, wayfActionPath, selectedIdpUrl,
                        username, password);

                // Apenas mostra o recurso que o usurio queria acessar (neste caso, mostra a pg. de
                // "Homologao de atributos").
                Intent newIntent = new Intent(ShibAuthenticationActivity.this.getApplicationContext(),
                        TestActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("arg", authResult);
                newIntent.putExtras(bundle);
                startActivity(newIntent);

            } catch (IOException e) {
                String message = "IOException - problema na conexo";
                Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
                toast.show();
            } catch (Exception e) {
                String message = "Exception - problema na autenticao";
                Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
                toast.show();
            }
        }
    });

    backButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

}

From source file:com.stanzione.licensesmanagement.ui.CreateProjectFragment.java

@Override
public void onOperationSuccess(Object returnObject, int operationCode) {

    Log.d(TAG, "Operation success!");

    if (operationCode == CODE_LIST_COMPANY) {

        companyArrayList = (ArrayList<Company>) returnObject;
        ArrayList<String> companyNameArrayList = new ArrayList<String>();

        for (int i = 0; i < companyArrayList.size(); i++) {
            companyNameArrayList.add(companyArrayList.get(i).getName());
        }/*from   www  .ja v  a2 s .c o m*/

        ArrayAdapter<String> companyAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1, companyNameArrayList);
        companyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        projectCompanyNameSpinner.setAdapter(companyAdapter);

    } else if (operationCode == CODE_CREATE_PROJECT) {

        Toast.makeText(getActivity(), "Project created successfully!", Toast.LENGTH_LONG).show();

    }

    progressBar.setVisibility(View.INVISIBLE);

}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void initializeExerciseSpinner() {
    // La idea de esta funcin es crear los elementos del spinner utilizando
    // los arrays definidos en los recursos

    mExercises = new ArrayList<Exercise>();
    addExerciseModule(mExercises, R.array.codes);
    addExerciseModule(mExercises, R.array.digital_systems);
    addExerciseModule(mExercises, R.array.networks);

    ArrayAdapter<Exercise> adapter = new ArrayAdapter<Exercise>(getActivity(),
            android.R.layout.simple_spinner_item, mExercises);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mExerciseSpinner = (Spinner) mRootView.findViewById(R.id.spinner_exercise);
    mExerciseSpinner.setAdapter(adapter);

    mExerciseSpinner.setOnItemSelectedListener(this);
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void initializeLevelSpinner() {
    ArrayList<String> levelNames = new ArrayList<String>();

    TypedArray array = getResources().obtainTypedArray(R.array.pref_level_values);

    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        int resourceId = array.getResourceId(i, defaultId);

        String name = getResources().getString(resourceId);
        levelNames.add(name);/*from   w w  w  . j  a v a  2s.co  m*/
    }

    array.recycle();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            levelNames);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mLevelSpinner = (Spinner) mRootView.findViewById(R.id.spinner_level);
    mLevelSpinner.setAdapter(adapter);

    mLevelSpinner.setOnItemSelectedListener(this);
}

From source file:com.akoscz.youtube.YouTubeRecyclerViewFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);/*from w w  w . jav  a2s  .  com*/
    if (getArguments() != null) {
        mPlaylistIds = getArguments().getStringArray(ARG_YOUTUBE_PLAYLIST_IDS);
    }

    // start fetching the playlist titles
    new GetPlaylistTitlesAsyncTask(mYouTubeDataApi) {
        @Override
        protected void onPostExecute(PlaylistListResponse playlistListResponse) {
            super.onPostExecute(playlistListResponse);
            mPlaylistTitles = new ArrayList();
            for (com.google.api.services.youtube.model.Playlist playlist : playlistListResponse.getItems()) {
                mPlaylistTitles.add(playlist.getSnippet().getTitle());
            }
            // update the spinner adapter with the titles of the playlists
            ArrayAdapter<List<String>> spinnerAdapter = new ArrayAdapter(getContext(),
                    android.R.layout.simple_spinner_item, mPlaylistTitles);
            spinnerAdapter.setDropDownViewResource(SPINNER_ITEM_DROPDOWN_LAYOUT_ID);
            mPlaylistSpinner.setAdapter(spinnerAdapter);
        }
    }.execute(mPlaylistIds);
}