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.xyproto.archfriend.ArchFriendActivity.java

private void populateSpinner() throws InterruptedException, ExecutionException {
    Spinner spinner = (Spinner) findViewById(R.id.lstMaintainers);

    List<Maintainer> maintainers = ArchWeb.getMaintainers();

    if (!maintainers.isEmpty()) {
        ArrayAdapter<Maintainer> adapter = new ArrayAdapter<Maintainer>(this,
                android.R.layout.simple_spinner_item, maintainers);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);/*from   w  w w . ja  v  a  2  s .co  m*/

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapter, View v, int i, long lng) {
                TextView tvNews = (TextView) findViewById(R.id.txtArchNews);
                Maintainer maintainer = (Maintainer) adapter.getAdapter().getItem(i);

                String outputText = null;
                try {
                    List<Package> packages = ArchWeb.getFlaggedPackages(maintainer);

                    outputText = maintainer.getFullName();
                    if (packages.isEmpty()) {
                        outputText += " "
                                + String.format(getString(R.string.flagged_ood), getString(R.string.zero));
                    } else if (packages.size() == 1) {
                        outputText += " " + getString(R.string.only_one);
                        outputText += "\n\n" + packages.get(0);
                    } else {
                        outputText += " " + String.format(getString(R.string.flagged_ood), packages.size());
                        outputText += "\n\n";
                        for (Package pkg : packages) {
                            outputText += pkg + "\n";
                        }
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                if (spinnerCanChangeStuffYet) {
                    if (outputText != null)
                        tvNews.setText(outputText);
                    else
                        tvNews.setText(R.string.no_maintainers);

                    scrollHome();
                } else {
                    // This is to avoid the spinner from overwriting the
                    // news with the initial default selection
                    spinnerCanChangeStuffYet = true;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                TextView tv = (TextView) findViewById(R.id.txtArchNews);
                if (spinnerCanChangeStuffYet) {
                    tv.setText("");
                    scrollHome();
                }
            }

        });
    } else {
        spinner.setVisibility(View.INVISIBLE);
        TextView tvNoData = (TextView) findViewById(R.id.tvNoData);
        tvNoData.setVisibility(View.VISIBLE);
    }
}

From source file:com.todoroo.astrid.gcal.GCalControlSet.java

@Override
protected void afterInflate() {
    calendarSelector = (Spinner) getView().findViewById(R.id.calendars);
    calendar = (TextView) getView().findViewById(R.id.calendar_display_which);
    calendar.setOnClickListener(new OnClickListener() {
        @Override/*from  w w  w. j av a 2s  . co  m*/
        public void onClick(View v) {
            if (!hasEvent) {
                calendarSelector.performClick();
            } else {
                viewCalendarEvent();
            }
        }
    });
    ArrayList<String> items = new ArrayList<>();
    Collections.addAll(items, calendars.calendars);
    items.add(0, activity.getString(R.string.gcal_TEA_nocal));

    ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item,
            items.toArray(new String[items.size()]));

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    calendarSelector.setPromptId(title);
    calendarSelector.setAdapter(adapter);
    resetCalendarSelector();
    calendarSelector.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            refreshDisplayView();
        }

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

From source file:com.asksven.betterbatterystats.RawStatsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.raw_stats);// ww w.j a v  a 2 s  .c  o m

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.label_raw_stats));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(false);

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);

    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            doRefresh();
        }
    });

    // Spinner for selecting the stat
    Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat);

    ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats,
            R.layout.bbs_spinner_layout);
    spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);

    spinnerStat.setAdapter(spinnerStatAdapter);
    // setSelection MUST be called after setAdapter
    spinnerStat.setSelection(m_iStat);
    spinnerStat.setOnItemSelectedListener(this);

    TextView tvSince = (TextView) findViewById(R.id.TextViewSince);

    long sinceMs = SystemClock.elapsedRealtime();

    if (sinceMs != -1) {
        String sinceText = DateUtils.formatDuration(sinceMs);

        tvSince.setText(sinceText);
        Log.i(TAG, "Since " + sinceText);
    } else {
        tvSince.setText("n/a ");
        Log.i(TAG, "Since: n/a ");

    }

}

From source file:com.example.linhdq.test.documents.creation.visualisation.LayoutQuestionDialog.java

@NonNull
@Override//from www  .  jav a 2s.co  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getContext();
    mLayout = null;
    Pair<String, String> language = PreferencesUtils.getOCRLanguage(context);

    final InstallStatus installStatus = OcrLanguageDataStore.isLanguageInstalled(language.first, context);

    if (!installStatus.isInstalled()) {
        final String defaultLanguage = context.getString(R.string.default_ocr_language);
        final String defaultLanguageDisplay = context.getString(R.string.default_ocr_display_language);
        language = Pair.create(defaultLanguage, defaultLanguageDisplay);
    }
    mLanguage = language.first;

    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    View layout = View.inflate(context, R.layout.dialog_layout_question, null);
    builder.setView(layout);

    final ViewFlipper titleViewFlipper = (ViewFlipper) layout.findViewById(R.id.layout_title);
    final ImageView columnLayout = (ImageView) layout.findViewById(R.id.column_layout);
    final ImageView pageLayout = (ImageView) layout.findViewById(R.id.page_layout);
    final ImageSwitcher fairy = (ImageSwitcher) layout.findViewById(R.id.fairy_layout);
    fairy.setFactory(new ViewSwitcher.ViewFactory() {
        public View makeView() {
            return new ImageView(context);
        }
    });
    fairy.setImageResource(R.drawable.fairy_looks_center);
    fairy.setInAnimation(context, android.R.anim.fade_in);
    fairy.setOutAnimation(context, android.R.anim.fade_out);

    final int color = context.getResources().getColor(R.color.progress_color);

    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.LIGHTEN);

    columnLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.COMPLEX) {
                fairy.setImageResource(R.drawable.fairy_looks_left);
                titleViewFlipper.setDisplayedChild(2);
                columnLayout.setColorFilter(colorFilter);
                pageLayout.clearColorFilter();
                mLayout = LayoutKind.COMPLEX;
            }

        }
    });
    pageLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mLayout != LayoutKind.SIMPLE) {
                mLayout = LayoutKind.SIMPLE;
                titleViewFlipper.setDisplayedChild(1);
                fairy.setImageResource(R.drawable.fairy_looks_right);
                pageLayout.setColorFilter(colorFilter);
                columnLayout.clearColorFilter();
            }
        }
    });

    final Spinner langButton = (Spinner) layout.findViewById(R.id.button_language);
    List<OcrLanguage> installedLanguages = OcrLanguageDataStore.getInstalledOCRLanguages(context);

    // actual values uses by tesseract
    final ArrayAdapter<OcrLanguage> adapter = new ArrayAdapter<>(context, R.layout.item_spinner_language,
            installedLanguages);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    langButton.setAdapter(adapter);
    for (int i = 0; i < installedLanguages.size(); i++) {
        OcrLanguage lang = installedLanguages.get(i);
        if (lang.getValue().equals(language.first)) {
            langButton.setSelection(i, false);
            break;
        }
    }
    langButton.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final OcrLanguage item = adapter.getItem(position);
            mLanguage = item.getValue();
            PreferencesUtils.saveOCRLanguage(context, item);
        }

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

        }
    });

    builder.setPositiveButton(R.string.start_scan, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            if (mLayout == null) {
                mLayout = LayoutKind.SIMPLE;
            }
            LayoutChoseListener listener = (LayoutChoseListener) getActivity();
            listener.onLayoutChosen(mLayout, mLanguage);
            dialog.dismiss();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            getActivity().finish();
            dialog.dismiss();
        }
    });

    return builder.create();

}

From source file:au.org.ala.fielddata.mobile.SurveyBuilder.java

private Spinner buildSpinner(Attribute attribute, ViewGroup parent) {

    ViewGroup row = (ViewGroup) viewContext.getLayoutInflater().inflate(R.layout.input_spinner_view, parent);

    Spinner spinner = (Spinner) row.findViewById(R.id.spinner);
    spinner.setPrompt("Select " + attribute.description);
    ArrayList<AttributeOption> options = new ArrayList<Attribute.AttributeOption>(attribute.options.length + 1);
    options.addAll(Arrays.asList(attribute.options));

    ArrayAdapter<AttributeOption> adapter = new ArrayAdapter<AttributeOption>(viewContext,
            R.layout.multiline_spinner_item, options);
    adapter.setDropDownViewResource(R.layout.multiline_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*from  www  .  jav a  2  s  .c om*/

    return spinner;
}

From source file:com.nextgis.maplibui.CreateRemoteTMSLayerDialog.java

@NonNull
@Override/*from  ww w.ja va  2 s.c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view = inflater.inflate(R.layout.layout_create_tms, null);

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context,
            android.R.layout.simple_spinner_item);
    mSpinner = (Spinner) view.findViewById(R.id.layer_type);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(adapter);

    adapter.add(context.getString(R.string.tmstype_osm));
    adapter.add(context.getString(R.string.tmstype_normal));

    mInput = (EditText) view.findViewById(R.id.layer_name);
    mUrl = (EditText) view.findViewById(R.id.layer_url);

    mLogin = (EditText) view.findViewById(R.id.login);
    mPassword = (EditText) view.findViewById(R.id.password);

    if (null == savedInstanceState) {
        //mInput.setText(context.getResources().getText(R.string.osm));
        //mUrl.setText(context.getResources().getText(R.string.osm_url));
        //mSpinner.setSelection(0);
    } else {
        mInput.setText(savedInstanceState.getString(KEY_NAME));
        mUrl.setText(savedInstanceState.getString(KEY_URL));
        mLogin.setText(savedInstanceState.getString(KEY_LOGIN));
        mPassword.setText(savedInstanceState.getString(KEY_PASSWORD));
        mSpinner.setSelection(savedInstanceState.getInt(KEY_POSITION));
        mTitle = savedInstanceState.getString(KEY_TITLE);
        short id = savedInstanceState.getShort(KEY_ID);
        MapBase map = MapBase.getInstance();
        if (null != map) {
            ILayer iLayer = map.getLayerById(id);
            if (iLayer instanceof LayerGroup)
                mGroupLayer = (LayerGroup) iLayer;
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(mTitle).setIcon(R.drawable.ic_remote_tms).setView(view)
            .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (mSpinner.getSelectedItemPosition()) {
                    case 0:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 1:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }
                    String layerName = mInput.getText().toString();
                    String layerURL = mUrl.getText().toString();
                    String layerLogin = mLogin.getText().toString();
                    String layerPassword = mPassword.getText().toString();

                    //check if {x}, {y} or {z} present
                    if (!layerURL.contains("{x}") || !layerURL.contains("{y}") || !layerURL.contains("{z}")) {
                        Toast.makeText(context, R.string.error_invalid_url, Toast.LENGTH_SHORT).show();
                        return;
                    }

                    if (!layerURL.startsWith("http"))
                        layerURL = "http://" + layerURL;

                    //create new layer and store it and add it to the map
                    RemoteTMSLayerUI layer = new RemoteTMSLayerUI(mGroupLayer.getContext(),
                            mGroupLayer.cretateLayerStorage());
                    layer.setName(layerName);
                    layer.setURL(layerURL);
                    layer.setLogin(layerLogin);
                    layer.setPassword(layerPassword);
                    layer.setTMSType(tmsType);
                    layer.setVisible(true);

                    mGroupLayer.addLayer(layer);
                    mGroupLayer.save();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:com.armtimes.dialogs.DialogSettings.java

private void initImageQualityControllers(final View view) {
    Spinner spinner = (Spinner) view.findViewById(R.id.spinnerImageQuality);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_quality_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);//from   w  w  w  . ja va  2 s .c  om
    spinner.setSelection(getImageQuality(getActivity()));

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setImageQuality(getActivity(), position);
        }

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

From source file:com.fachri.makers.pets.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the pet.
 *///from ww  w .  jav a 2s. com
private void setupSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options,
            android.R.layout.simple_spinner_item);

    // Specify dropdown layout style - simple list view with 1 item per line
    genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    // Apply the adapter to the spinner
    mGenderSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selection = (String) parent.getItemAtPosition(position);
            if (!TextUtils.isEmpty(selection)) {
                if (selection.equals(getString(R.string.gender_male))) {
                    mGender = 1; // Male
                } else if (selection.equals(getString(R.string.gender_female))) {
                    mGender = 2; // Female
                } else {
                    mGender = 0; // Unknown
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mGender = 0; // Unknown
        }
    });
}

From source file:com.mifos.mifosxdroid.online.createnewcenter.CreateNewCenterFragment.java

@Override
public void showOffices(List<Office> offices) {
    final List<String> officeList = new ArrayList<String>();

    for (Office office : offices) {
        officeList.add(office.getName());
        officeNameIdHashMap.put(office.getName(), office.getId());
    }//from w ww .j  a  v a 2  s  . c  o  m
    ArrayAdapter<String> officeAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, officeList);
    officeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_offices.setAdapter(officeAdapter);
    sp_offices.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            officeId = officeNameIdHashMap.get(officeList.get(i));
            Log.d("officeId " + officeList.get(i), String.valueOf(officeId));
            if (officeId != -1) {

            } else {
                Toast.makeText(getActivity(), getString(R.string.error_select_office), Toast.LENGTH_SHORT)
                        .show();
            }
        }

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

        }
    });
}

From source file:it.uniroma2.foundme.studente.RegistrationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registration);
    context = this;
    btSignUp = (Button) findViewById(R.id.btSignUp);

    etNewUser = (EditText) findViewById(R.id.etNewUser);
    etNewPass1 = (EditText) findViewById(R.id.etNewPass);
    etNewPass2 = (EditText) findViewById(R.id.etNewPass2);
    etNewMail = (EditText) findViewById(R.id.etNewMail);
    etNewMail2 = (EditText) findViewById(R.id.etNewMail2);
    etNewId = (EditText) findViewById(R.id.etNewId);
    spDept = (Spinner) findViewById(R.id.spDept);

    final ArrayAdapter<CharSequence> adapter = createFromResource(this, R.array.Departments,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spDept.setAdapter(adapter);// www.jav a 2  s .c  o  m

    spDept.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        protected Adapter initializedAdapter = null;

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            if (initializedAdapter != parentView.getAdapter()) {
                initializedAdapter = parentView.getAdapter();
                return;
            }

            Dept = parentView.getItemAtPosition(position).toString();

        }

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

    btSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            NewUser = etNewUser.getText().toString();
            NewPass1 = etNewPass1.getText().toString();
            NewPass2 = etNewPass2.getText().toString();
            NewMail = etNewMail.getText().toString();
            NewMail2 = etNewMail2.getText().toString();
            NewId = etNewId.getText().toString();

            if (checkPlayServices()) {
                gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
                if (!checkLoginData(NewPass1, NewPass2, NewMail, NewMail2, Dept)) {
                    Toast.makeText(getApplicationContext(), Variables_it.FILL_FIELD, Toast.LENGTH_LONG).show();
                } else {
                    try {
                        manageRegistration(NewUser, NewPass1, NewMail, NewId, Dept);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });

}