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:edu.teco.context.ui.Tab2Fragment.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;
    }/*www  .  jav a  2 s .c  o  m*/

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

    // make a copy of the context labels
    List<String> contextLabels = new ArrayList<String>(FrameworkConfiguration.getInstance().getContextLabels());

    final Spinner spinner = (Spinner) v.findViewById(R.id.spinner_activities_training);
    // 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, contextLabels);
    // 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);

    return v;
}

From source file:edu.teco.context.ui.Tab4Fragment.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 w  w  w  .j a  v a2  s. c o  m*/

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

    // make a copy of the context labels
    List<String> contextLabels = new ArrayList<String>(FrameworkConfiguration.getInstance().getContextLabels());

    final Spinner spinner = (Spinner) v.findViewById(R.id.spinner_activities_evaluation);
    // 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, contextLabels);
    // 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);

    return v;
}

From source file:com.battlelancer.seriesguide.ui.FirstRunFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // add button
    getView().findViewById(R.id.buttonFirstRunAddShow).setOnClickListener(new OnClickListener() {
        @Override//from   w w w.j  a va  2  s.c  o  m
        public void onClick(View v) {
            fireTrackerEvent("Add show");
            startActivity(new Intent(getActivity(), AddActivity.class));
            setFirstRunDismissed();
        }
    });

    // language chooser
    Spinner spinner = (Spinner) getView().findViewById(R.id.welcome_setuplanguage);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.languages,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new OnLanguageSelectedListener());

    // trakt connect button
    getView().findViewById(R.id.welcome_setuptrakt).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            fireTrackerEvent("Connect trakt");

            Intent i = new Intent(getActivity(), ConnectTraktActivity.class);
            startActivity(i);
        }
    });

    // dismiss button
    View buttonDismiss = getView().findViewById(R.id.buttonFirstRunDismiss);
    CheatSheet.setup(buttonDismiss);
    buttonDismiss.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            fireTrackerEvent("Dismiss");
            setFirstRunDismissed();
        }
    });

    setHasOptionsMenu(true);
}

From source file:com.hardcopy.retrowatchle.WatchControlFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_watch_control, container, false);

    mEditGmailAddr = (EditText) rootView.findViewById(R.id.edit_email_addr);
    String defaultAddr = Settings.getInstance(mContext).getGmailAddress();
    if (defaultAddr != null && !defaultAddr.isEmpty())
        mEditGmailAddr.setText(defaultAddr);
    mEditGmailAddr.addTextChangedListener(new TextWatcher() {
        @Override// w  w w .ja v a 2s.  c  o m
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String addr = s.toString();
            if (addr != null && !addr.isEmpty()) {
                mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_SET_EMAIL_ADDRESS, 0, 0,
                        addr, null, null);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    mSpinnerClockStyle = (Spinner) rootView.findViewById(R.id.spinner_clock_style);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.clock_style_array,
            R.layout.spinner_simple_item2);
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item);
    mSpinnerClockStyle.setPrompt(mContext.getString(R.string.clock_style_title));
    mSpinnerClockStyle.setAdapter(adapter);
    mSpinnerClockStyle.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mPresetClockStyle > -1 && mPresetClockStyle != position) {
                mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_CLOCK_STYLE, position,
                        0, null, null, null);
            }
            mPresetClockStyle = position;
        }

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

    mSpinnerIndicator = (Spinner) rootView.findViewById(R.id.spinner_show_indicator);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(mContext,
            R.array.clock_indicator_array, R.layout.spinner_simple_item2);
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item);
    mSpinnerIndicator.setPrompt(mContext.getString(R.string.clock_indicator_title));
    mSpinnerIndicator.setAdapter(adapter2);
    mSpinnerIndicator.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mPresetIndicator > -1 && mPresetIndicator != position) {
                mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_SHOW_INDICATOR,
                        position, 0, null, null, null);
            }
            mPresetIndicator = position;
        }

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

    // 'Run in background' setting
    mCheckBackground = (CheckBox) rootView.findViewById(R.id.check_background_service);
    mCheckBackground.setChecked(Settings.getInstance(mContext).getRunInBackground());
    mCheckBackground.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Settings.getInstance(mContext).setRunInBackground(isChecked);
            mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_RUN_IN_BACKGROUND, 0, 0,
                    null, null, null);
        }
    });

    return rootView;
}

From source file:com.gh4a.ExploreActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(Gh4Application.THEME);/* w  w w.  j ava2 s  .  co m*/
    super.onCreate(savedInstanceState);

    mExploreItem = getIntent().getExtras().getInt("exploreItem");

    if (!isOnline()) {
        setErrorView();
        return;
    }

    setContentView(R.layout.explore);

    mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayHomeAsUpEnabled(true);

    Context context = getSupportActionBar().getThemedContext();
    ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.explore_item,
            R.layout.sherlock_spinner_item);
    list.setDropDownViewResource(R.layout.row_simple);

    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setListNavigationCallbacks(list, this);
    getSupportActionBar().setSelectedNavigationItem(mExploreItem);

    setPageIndicator();
}

From source file:com.hardcopy.retrowatch.WatchControlFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_watch_control, container, false);

    mEditGmailAddr = (EditText) rootView.findViewById(R.id.edit_email_addr);
    String defaultAddr = Settings.getInstance(mContext).getGmailAddress();
    if (defaultAddr != null && !defaultAddr.isEmpty())
        mEditGmailAddr.setText(defaultAddr);
    mEditGmailAddr.addTextChangedListener(new TextWatcher() {
        @Override/*from ww  w.ja  va 2s .  c  om*/
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String addr = s.toString();
            if (addr != null && !addr.isEmpty()) {
                mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_SET_EMAIL_ADDRESS, 0, 0,
                        addr, null, null);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    mSpinnerClockStyle = (Spinner) rootView.findViewById(R.id.spinner_clock_style);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.clock_style_array,
            R.layout.spinner_simple_item2);
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item);
    mSpinnerClockStyle.setPrompt(mContext.getString(R.string.clock_style_title));
    mSpinnerClockStyle.setAdapter(adapter);
    mSpinnerClockStyle.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mPresetClockStyle > -1 && mPresetClockStyle != position) {
                mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_CLOCK_STYLE, position,
                        0, null, null, null);
            }
            mPresetClockStyle = position;
        }

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

    // Clock indicator style selector
    mSpinnerIndicator = (Spinner) rootView.findViewById(R.id.spinner_show_indicator);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(mContext,
            R.array.clock_indicator_array, R.layout.spinner_simple_item2);
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item);
    mSpinnerIndicator.setPrompt(mContext.getString(R.string.clock_indicator_title));
    mSpinnerIndicator.setAdapter(adapter2);
    mSpinnerIndicator.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mPresetIndicator > -1 && mPresetIndicator != position) {
                mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_SHOW_INDICATOR,
                        position, 0, null, null, null);
            }
            mPresetIndicator = position;
        }

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

    // 'Run in background' setting
    mCheckBackground = (CheckBox) rootView.findViewById(R.id.check_background_service);
    mCheckBackground.setChecked(Settings.getInstance(mContext).getRunInBackground());
    mCheckBackground.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Settings.getInstance(mContext).setRunInBackground(isChecked);
            mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_REQUEST_RUN_IN_BACKGROUND, 0, 0,
                    null, null, null);
        }
    });

    return rootView;
}

From source file:com.bangalore.barcamp.activity.ShareActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share_screen);
    mDrawerToggle = BCBFragmentUtils.setupActionBar(this, "Share");

    // BCBUtils.createActionBarOnActivity(this);
    // BCBUtils.addNavigationActions(this);
    ((EditText) findViewById(R.id.editText1)).addTextChangedListener(new TextWatcher() {

        @Override/*from  ww  w .  j  a v  a  2 s . c  o  m*/
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: " + (140 - s.length() - 7));
        }
    });
    if (getIntent().hasExtra(SHARE_STRING)) {
        ((EditText) findViewById(R.id.editText1)).setText(getIntent().getStringExtra(SHARE_STRING));
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final Spinner spinner = (Spinner) findViewById(R.id.shareTypeSpinner);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
    String selectedItem = BCBSharedPrefUtils.getShareSettings(getApplicationContext());
    int selectedPos = -1;
    for (ResolveInfo info : matches) {
        adapter.add(info.loadLabel(pm));
        if (selectedItem.equals(info.loadLabel(pm))) {
            selectedPos = matches.indexOf(info);
        }
    }
    spinner.setAdapter(adapter);

    if (selectedPos != -1) {
        spinner.setSelected(true);
        spinner.setSelection(selectedPos);
    }
    ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: 140");
    ((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            int appSelectedPos = spinner.getSelectedItemPosition();
            ResolveInfo info = matches.get(appSelectedPos);
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);

            BCBSharedPrefUtils.setShareSettings(getApplicationContext(), (String) info.loadLabel(pm));
            intent.putExtra(Intent.EXTRA_TEXT,
                    ((EditText) findViewById(R.id.editText1)).getText().toString() + " #barcampblr");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(intent);
            finish();

        }
    });

    BCBFragmentUtils.addNavigationActions(this);
    supportInvalidateOptionsMenu();
    Tracker t = ((BarcampBangalore) getApplication()).getTracker();

    // Set screen name.
    t.setScreenName(this.getClass().getName());

    // Send a screen view.
    t.send(new HitBuilders.AppViewBuilder().build());

}

From source file:de.awisus.refugeeaidleipzig.views.signup.FragmentSignup.java

/**
 * Private method that creates an Array Adapter the spinner uses to show accommodation names
 *//* w w  w. ja va 2  s .  c  om*/
private void initSpinnerAdapter() {

    LinkedList<Unterkunft> unterkuenfte;
    unterkuenfte = model.getUnterkuenfte().asList();
    Collections.sort(unterkuenfte);

    ArrayAdapter<Unterkunft> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item,
            unterkuenfte);

    // 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
    spUnterkunft.setAdapter(adapter);
}

From source file:fr.cph.stock.android.activity.OverallActivity.java

private void showPanelUpdateHistory() {
    final Dialog alert = new Dialog(this);
    alert.setTitle("Update history");
    alert.setContentView(R.layout.history_dialog);

    final Spinner checked = (Spinner) alert.findViewById(R.id.accountList);
    List<String> list = new ArrayList<String>();
    for (Account acc : portfolio.getAccounts()) {
        list.add(acc.getName());/*ww  w . j av a  2 s.  c  om*/
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    checked.setAdapter(dataAdapter);

    Button dialogButton = (Button) alert.findViewById(R.id.dialogButtonOK);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshItem.setActionView(R.layout.progressbar);
            refreshItem.expandActionView();
            Account account = portfolio.getAccounts().get(checked.getSelectedItemPosition());
            EditText liquidityView = (EditText) alert.findViewById(R.id.liquidityMov);
            EditText yieldView = (EditText) alert.findViewById(R.id.yield);
            EditText buyView = (EditText) alert.findViewById(R.id.buy);
            EditText sellView = (EditText) alert.findViewById(R.id.sell);
            EditText taxeView = (EditText) alert.findViewById(R.id.taxe);
            EditText commentaryView = (EditText) alert.findViewById(R.id.commentaryEditText);

            String params = null;
            params = "?accountId=" + account.getId() + "&liquidity=" + liquidityView.getText() + "&yield="
                    + yieldView.getText() + "&buy=" + buyView.getText() + "&sell=" + sellView.getText()
                    + "&taxe=" + taxeView.getText() + "&commentary="
                    + commentaryView.getText().toString().replaceAll(" ", "%20");
            MainTask mainTask = new MainTask(OverallActivity.this, UrlType.UPDATEHISTORY, params);
            mainTask.execute((Void) null);
            alert.dismiss();
        }
    });
    dialogButton = (Button) alert.findViewById(R.id.dialogButtonCancel);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            alert.dismiss();
        }
    });
    alert.show();
}

From source file:de.uhrenbastler.watchcheck.ui.LogDialog.java

public LogDialog(Context context, Bundle logData) {
    super(context);

    setContentView(R.layout.log_dialog);
    setTitle(getContext().getString(R.string.enterLog));
    setCancelable(true);//from w w  w.java 2  s  . c  o m

    Button buttonSave = (Button) findViewById(R.id.buttonSave);
    buttonSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            makeLogEntry();
            saved = true;
            dismiss();
        }
    });

    watchId = logData.getInt(ATTR_WATCH_ID);
    deviation = logData.getDouble(ATTR_DEVIATION);
    modeNtp = logData.getBoolean(ATTR_MODE_NTP);
    localTime = (GregorianCalendar) logData.get(ATTR_LOCAL_TIME);
    ntpTime = (GregorianCalendar) logData.get(ATTR_NTP_TIME);
    lastLog = (Log) logData.get(ATTR_LAST_LOG);

    Logger.debug("watchId=" + watchId + ", deviation=" + deviation + ", modeNtp=" + modeNtp + ", localTime="
            + localTime.getTime() + ", ntpTime=" + (ntpTime != null ? ntpTime.getTime() : "NULL") + ", lastLog="
            + lastLog);

    TextView textDeviation = (TextView) findViewById(R.id.textViewDeviationValue);
    DecimalFormat df = new DecimalFormat("#.#");

    textDeviation.setText(
            (deviation > 0 ? "+" : deviation < 0 ? "-" : "+-") + df.format(Math.abs(deviation)) + " sec.");

    positionSpinner = (Spinner) findViewById(R.id.logSpinnerPosition);
    ArrayAdapter<?> positionAdapter = ArrayAdapter.createFromResource(getContext(), R.array.positions,
            android.R.layout.simple_spinner_item);
    positionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    positionSpinner.setAdapter(positionAdapter);

    if (lastLog != null && lastLog.getPosition() != null)
        positionSpinner.setSelection(ArrayUtils.indexOf(POSITIONARR, lastLog.getPosition()));
    else
        positionSpinner.setSelection(0);

    temperatureSpinner = (Spinner) findViewById(R.id.logSpinnerTemperature);
    ArrayAdapter<?> temperatureAdapter = ArrayAdapter.createFromResource(getContext(), R.array.temperatures,
            android.R.layout.simple_spinner_item);
    temperatureAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    temperatureSpinner.setAdapter(temperatureAdapter);

    if (lastLog != null)
        temperatureSpinner.setSelection(ArrayUtils.indexOf(TEMPARR, lastLog.getTemperature()));
    else
        temperatureSpinner.setSelection(0);

    comment = (EditText) findViewById(R.id.logComment);

    startFlag = (CheckBox) findViewById(R.id.logCheckBoxNewPeriod);
    startFlag.setChecked(lastLog == null);
    startFlag.setEnabled(lastLog != null);
}