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.commonsware.android.contacts.spinners.ContactSpinners.java

@Override
public void onReady() {
    setContentView(R.layout.main);//w  w  w  . j av a  2s . c om

    Spinner spin = findViewById(R.id.spinner);
    spin.setOnItemSelectedListener(this);

    ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.options));

    aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(aa);

    RecyclerView rv = findViewById(android.R.id.list);

    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    adapter = new RVCursorAdapter(getLayoutInflater());
    rv.setAdapter(adapter);
}

From source file:com.elkriefy.android.apps.permissionmigrationguide.MainActivity.java

private void populateSpinner() {
    List<String> list = new ArrayList<>();
    list.add("No permissions check");
    list.add("Android Marshmallow permissions");
    list.add("Support Library Permissions");
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(dataAdapter);/*from  w  w w .ja  va 2s.  c o  m*/
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mGoogleApiClient.isConnected()) {
                mGoogleApiClient.disconnect();
            }
            switch (position) {
            case NO_PERMISSIONS_CHECK:
                mState = NO_PERMISSIONS_CHECK;
                break;
            case MARSHMALLOW_PERMISSIONS_CHECK:
                mState = MARSHMALLOW_PERMISSIONS_CHECK;
                break;
            case SUPPORT_LIBRARY_PERMISSION_CHECK:
                mState = SUPPORT_LIBRARY_PERMISSION_CHECK;
                break;
            }
            mGoogleApiClient.connect();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            if (mGoogleApiClient.isConnected()) {
                mGoogleApiClient.disconnect();
            }
        }
    });
}

From source file:eu.geopaparazzi.library.core.dialogs.ZoomlevelDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View labelDialogView = getActivity().getLayoutInflater().inflate(R.layout.fragment_dialog_zoomlevel, null);
    builder.setView(labelDialogView);//from w  w  w . j ava2s  .c o  m

    String minStr = mMinMaxZoomlevels[0] + "";
    String maxStr = mMinMaxZoomlevels[1] + "";
    int minIndex = 0;
    int maxIndex = 0;
    for (int i = 0; i < allZoomlevels.length; i++) {
        if (allZoomlevels[i].equals(minStr)) {
            minIndex = i;
        }
        if (allZoomlevels[i].equals(maxStr)) {
            maxIndex = i;
        }
    }
    final Spinner minSpinner = (Spinner) labelDialogView.findViewById(R.id.minZoomLevelSpinner);
    ArrayAdapter<String> zoomlevelSpinnerAdapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_spinner_item, allZoomlevels);
    zoomlevelSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    minSpinner.setAdapter(zoomlevelSpinnerAdapter);
    minSpinner.setSelection(minIndex);
    minSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Object selectedItem = minSpinner.getSelectedItem();
            String fieldStr = selectedItem.toString();
            mMinMaxZoomlevels[0] = Integer.parseInt(fieldStr);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // ignore
        }
    });

    final Spinner maxSpinner = (Spinner) labelDialogView.findViewById(R.id.maxZoomLevelSpinner);
    zoomlevelSpinnerAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item,
            allZoomlevels);
    zoomlevelSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    maxSpinner.setAdapter(zoomlevelSpinnerAdapter);
    maxSpinner.setSelection(maxIndex);
    maxSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Object selectedItem = maxSpinner.getSelectedItem();
            String fieldStr = selectedItem.toString();
            mMinMaxZoomlevels[1] = Integer.parseInt(fieldStr);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // ignore
        }
    });

    builder.setPositiveButton(R.string.set_properties, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            if (zoomlevelPropertiesChangeListener != null) {
                zoomlevelPropertiesChangeListener.onPropertiesChanged(mMinMaxZoomlevels[0],
                        mMinMaxZoomlevels[1]);
            }
        }
    });
    builder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    return builder.create(); // return dialog
}

From source file:ch.berta.fabio.popularmovies.presentation.ui.activities.MovieGridActivity.java

private void setupSorting() {
    mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    int sortSelected = mSharedPrefs.getInt(PERSIST_SORT, 0);

    Sort[] sortOptions = new Sort[] { new Sort(Sort.SORT_POPULARITY, getString(R.string.sort_popularity)),
            new Sort(Sort.SORT_RATING, getString(R.string.sort_rating)),
            new Sort(Sort.SORT_RELEASE_DATE, getString(R.string.sort_release_date)),
            new Sort(Sort.SORT_FAVORITE, getString(R.string.sort_favorite)) };
    ArrayAdapter<Sort> spinnerAdapter = new ArrayAdapter<>(this, R.layout.spinner_item_toolbar, sortOptions);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mBinding.spGridSort.setAdapter(spinnerAdapter);
    mBinding.spGridSort.setSelection(sortSelected, false);
    mBinding.spGridSort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from  w ww . jav a  2 s .co m*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            onSortOptionSelected((Sort) parent.getSelectedItem(), position);
        }

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

        }
    });
}

From source file:com.example.d062654.faciliman._3_IncidentDescription.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ll = (RelativeLayout) inflater.inflate(R.layout.incidentdescription, container, false);
    sendbutton = ((Button) ll.findViewById(R.id.descr_finished_button));
    sendbutton.setOnClickListener(this);
    locdescrp = ((TextView) ll.findViewById(R.id.detailed_location_description));
    locdescrp.setOnClickListener(this);
    damagdescrinfo = ((TextView) ll.findViewById(R.id.damage_description_information));
    damagdescrinfo.setOnClickListener(this);
    spinner = ((Spinner) ll.findViewById(R.id.facilities_spinner));
    title = (EditText) ll.findViewById(R.id.title);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(ll.getContext(), R.array.facilities,
            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);//from  ww  w .  j a  v a 2  s .c  o  m

    // Inflate the layout for this fragment
    return ll;
}

From source file:com.e3h.usmcknowledge.activities.ranks.Officer.java

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

    setContentView(R.layout.fragment_rank);

    sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
    sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
    sideNavigationView.setMenuClickCallback(this);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mLocations = getResources().getStringArray(R.array.rankofficer);

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

    // Activate Navigation Mode Tabs
    mActionBar = getSupportActionBar();/* w w w.  ja  v  a2 s  .  c  o m*/
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setListNavigationCallbacks(list, this);

    // Locate ViewPager in activity_main.xml
    mPager = (ViewPager) findViewById(R.id.pager);

    // Activate Fragment Manager
    FragmentManager fm = getSupportFragmentManager();

    // Capture ViewPager page swipes
    ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            // Find the ViewPager Position
            mActionBar.setSelectedNavigationItem(position);
        }
    };

    mPager.setOnPageChangeListener(ViewPagerListener);
    // Locate the adapter class called ViewPagerAdapter.java
    ViewPagerAdapterMainMenu viewpageradapter = new ViewPagerAdapterMainMenu(fm);
    // Set the View Pager Adapter into ViewPager
    mPager.setAdapter(viewpageradapter);

    // Capture tab button clicks
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // Pass the position on tab click to ViewPager
            mPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }
    };

    String[] menuItems = { "USMC", "Navy", "Air Force", "Army", "Coast Guard" };

    for (int i = 0; i < menuItems.length; i++) {
        String item = menuItems[i];
        tab = mActionBar.newTab().setText(item).setTabListener(tabListener);
        mActionBar.addTab(tab);
    }

}

From source file:com.e3h.usmcknowledge.activities.ranks.Warrant.java

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

    setContentView(R.layout.fragment_rank);

    sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
    sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
    sideNavigationView.setMenuClickCallback(this);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mLocations = getResources().getStringArray(R.array.rankwarrant);

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

    // Activate Navigation Mode Tabs
    mActionBar = getSupportActionBar();/*w  ww .ja  v  a 2 s.  c om*/
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setListNavigationCallbacks(list, this);

    // Locate ViewPager in activity_main.xml
    mPager = (ViewPager) findViewById(R.id.pager);

    // Activate Fragment Manager
    FragmentManager fm = getSupportFragmentManager();

    // Capture ViewPager page swipes
    ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            // Find the ViewPager Position
            mActionBar.setSelectedNavigationItem(position);
        }
    };

    mPager.setOnPageChangeListener(ViewPagerListener);
    // Locate the adapter class called ViewPagerAdapter.java
    ViewPagerAdapterMainMenu viewpageradapter = new ViewPagerAdapterMainMenu(fm);
    // Set the View Pager Adapter into ViewPager
    mPager.setAdapter(viewpageradapter);

    // Capture tab button clicks
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // Pass the position on tab click to ViewPager
            mPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
        }
    };

    String[] menuItems = { "USMC", "Navy", "Air Force", "Army", "Coast Guard" };

    for (int i = 0; i < menuItems.length; i++) {
        String item = menuItems[i];
        tab = mActionBar.newTab().setText(item).setTabListener(tabListener);
        mActionBar.addTab(tab);
    }

}

From source file:com.google.maps.android.utils.demo.HeatmapsDemoActivity.java

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 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  ww.  jav  a 2s .  c om*/
    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:can.yrt.onebusaway.ReportTripProblemFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Set the stop name.
    Bundle args = getArguments();// www .ja v  a  2s.co m
    final TextView tripName = (TextView) view.findViewById(R.id.trip_name);
    tripName.setText(MyTextUtils.toTitleCase(args.getString(TRIP_NAME)));

    // TODO: Switch this based on the trip mode
    final int tripArray = R.array.report_trip_problem_code_bus;

    //
    // The code spinner
    //
    mCodeView = (Spinner) view.findViewById(R.id.report_problem_code);
    ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(getActivity(), tripArray,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCodeView.setAdapter(adapter);

    // Comment
    mUserComment = (TextView) view.findViewById(R.id.report_problem_comment);

    // On vehicle
    mUserOnVehicle = (CheckBox) view.findViewById(R.id.report_problem_onvehicle);
    final View label = view.findViewById(R.id.report_problem_uservehicle_label);
    mUserVehicle = (TextView) view.findViewById(R.id.report_problem_uservehicle);
    // Disabled by default
    label.setEnabled(false);
    mUserVehicle.setEnabled(false);

    mUserOnVehicle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean checked = mUserOnVehicle.isChecked();
            label.setEnabled(checked);
            mUserVehicle.setEnabled(checked);
        }
    });

    if (savedInstanceState != null) {
        int position = savedInstanceState.getInt(CODE);
        mCodeView.setSelection(position);

        CharSequence comment = savedInstanceState.getCharSequence(USER_COMMENT);
        mUserComment.setText(comment);

        boolean onVehicle = savedInstanceState.getBoolean(USER_ON_VEHICLE);
        mUserOnVehicle.setChecked(onVehicle);

        CharSequence num = savedInstanceState.getCharSequence(USER_VEHICLE_NUM);
        mUserVehicle.setText(num);
        mUserVehicle.setEnabled(onVehicle);
    }
}

From source file:eu.geopaparazzi.library.core.dialogs.LabelDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View labelDialogView = getActivity().getLayoutInflater().inflate(R.layout.fragment_dialog_label, null);
    builder.setView(labelDialogView);/*from www. j a  va2 s . c  o m*/

    CheckBox visibilityCheckBox = (CheckBox) labelDialogView.findViewById(R.id.checkVisibility);
    visibilityCheckBox.setChecked(mCurrentLabelObject.hasLabel);
    visibilityCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mCurrentLabelObject.hasLabel = isChecked;
        }
    });

    mSizeTextView = (TextView) labelDialogView.findViewById(R.id.sizeTextView);
    mSizeTextView.setText(String.valueOf(mCurrentLabelObject.labelSize));
    SeekBar mSizeSeekBar = (SeekBar) labelDialogView.findViewById(R.id.sizeSeekBar);
    mSizeSeekBar.setOnSeekBarChangeListener(sizeChanged);
    mSizeSeekBar.setProgress(mCurrentLabelObject.labelSize);

    List<String> labelFieldsList = mCurrentLabelObject.labelFieldsList;
    int index = 0;
    for (int i = 0; i < labelFieldsList.size(); i++) {
        if (labelFieldsList.get(i).equals(mCurrentLabelObject.label)) {
            index = i;
            break;
        }
    }
    final Spinner fieldsSpinner = (Spinner) labelDialogView.findViewById(R.id.labelFieldSpinner);
    ArrayAdapter<String> fieldsSpinnerAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, labelFieldsList);
    fieldsSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fieldsSpinner.setAdapter(fieldsSpinnerAdapter);
    fieldsSpinner.setSelection(index);
    fieldsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Object selectedItem = fieldsSpinner.getSelectedItem();
            String fieldStr = selectedItem.toString();
            mCurrentLabelObject.label = fieldStr;
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // ignore
        }
    });

    builder.setPositiveButton(R.string.set_properties, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            if (labelPropertiesChangeListener != null) {
                labelPropertiesChangeListener.onPropertiesChanged(mCurrentLabelObject);
            }
        }
    });
    builder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    return builder.create(); // return dialog
}