Example usage for android.widget Spinner setAdapter

List of usage examples for android.widget Spinner setAdapter

Introduction

In this page you can find the example usage for android.widget Spinner setAdapter.

Prototype

@Override
public void setAdapter(SpinnerAdapter adapter) 

Source Link

Document

Sets the SpinnerAdapter used to provide the data which backs this Spinner.

Usage

From source file:com.glabs.homegenie.widgets.MediaServerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    _view = getActivity().getLayoutInflater().inflate(R.layout.widget_control_mediaserver, null);
    builder.setView(_view);/*from w  w w  .  java2s  .c  o  m*/

    builder.setMessage(_module.getDisplayName())
            .setPositiveButton("Play", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Play to...
                    playMediaTo();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog
                }
            });

    mAdapter = new MediaFilesAdapter(_view.getContext(), R.layout.widget_control_mediaserver_item,
            new ArrayList<MediaEntry>());
    final ListView lv = (ListView) _view.findViewById(R.id.filesList);
    lv.setAdapter(mAdapter);
    //
    if (navigationStack.size() == 0) {
        navigationStack.add("0");
    }
    //
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            MediaEntry clicked = mAdapter.getItem(i);
            mAdapter.setSelectedIndex(i);
            _selectedMedia = null;
            //
            if (clicked.Class.indexOf("object.container") == 0) {
                // browse to folder
                _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
                if (clicked.Title.equals(PARENT_FOLDER)) {
                    navigationStack.removeLast();
                } else {
                    navigationStack.add(clicked.Id);
                }
                browseMediaFolder(lv);
            } else {
                // set current media file
                _selectedMedia = clicked;
                _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }
        }
    });
    //

    Control.getGroupModules("", new Control.GetGroupModulesCallback() {
        @Override
        public void groupModulesUpdated(ArrayList<Module> modules) {
            ArrayAdapter<CharSequence> playtoitems = new ArrayAdapter<CharSequence>(_view.getContext(),
                    android.R.layout.simple_spinner_item);
            //
            playtoitems.add("This device");
            //
            for (int m = 0; m < modules.size(); m++) {
                Module module = modules.get(m);
                ModuleParameter devtype = module.getParameter("UPnP.StandardDeviceType");
                if (devtype != null && devtype.Value.equals("MediaRenderer")) {
                    renderers.add(module);
                    playtoitems.add(Control.getUpnpDisplayName(module));
                }
            }
            //
            // Media Renderer Spinner Select
            Spinner playto = (Spinner) _view.findViewById(R.id.playto);
            playto.setAdapter(playtoitems);
            playto.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    _selectedMediaRender = null;
                    if (i > 0) {
                        _selectedMediaRender = renderers.get(i - 1);
                    }
                }

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

                }
            });

        }
    });
    //
    browseMediaFolder(lv);

    // Create the AlertDialog object and return it
    _dialog = builder.create();
    _dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
        }
    });
    return _dialog;
}

From source file:com.example.mediasync3.DownloadPhoto.java

@Override
protected void onPostExecute(Boolean result) {
    mDialog.dismiss();//from  ww w  . j  av  a 2  s  . co  m

    if (pos == -2) {
        Spinner listSpin = (Spinner) rootView.findViewById(R.id.spinner1);
        listSpin.setAdapter(adapterList);
        listSpin.setEnabled(true);
    } else {

        ImageView iv = (ImageView) rootView.findViewById(R.id.image_view);

        fnames = mActivity.getPhotoNames();
        Drawable drawable = Drawable.createFromPath(LOCAL_PHOTO_DIR + "/" + fnames[pos]);
        iv.setImageDrawable(drawable);

        /*
        ListView lv = (ListView)rootView.findViewById(R.id.listView1);
        ArrayList<String> dir=new ArrayList<String>();
                
        //File sdCardRoot = Environment.getExternalStorageDirectory();
        final File PhotoDir = new File(LOCAL_PHOTO_DIR);
        for (File f : PhotoDir.listFiles()) {
           if (f.isFile())
        dir.add(f.getName());
        // Do your stuff
        }
        String[] localnames = dir.toArray(new String[dir.size()]);
                
        ArrayAdapter<String> ad = new ArrayAdapter<String>(mFrag.getActivity(), android.R.layout.simple_list_item_1,localnames);
        lv.setAdapter(ad);  
        */

        //TextView tv = (TextView) rootView.findViewById(R.id.textView1);
        //tv.setText(fnames[pos]);

    }

    if (result) {
        // Set the image now that we have it
        //    mView.setImageDrawable(mDrawable);
    } else {
        // Couldn't download it, so show an error
        //    showToast(mErrorMsg);
    }
}

From source file:com.heneryh.aquanotes.ui.controllers.OutletsDataAdapter.java

/** {@inheritDoc} */
@Override/*from w  w  w. j a  va2 s . c o  m*/
public void bindView(View view, Context context, Cursor cursor) {

    String outletName = cursor.getString(OutletDataViewQuery.NAME);
    ((TextView) view.findViewById(R.id.outlet_title)).setText(outletName);

    String deviceId = cursor.getString(OutletDataViewQuery.DEVICE_ID);
    ((TextView) view.findViewById(R.id.outlet_subtitle)).setText(deviceId);

    Spinner spinner = (Spinner) view.findViewById(R.id.spin);
    spinner.setAdapter(adapter);

    Integer controllerId = cursor.getInt(OutletDataViewQuery.CONTROLLER_ID);

    spinner.setOnItemSelectedListener(new myOnItemSelectedListener(outletName, controllerId));

    // Assign track color to visible block
    String val = cursor.getString(OutletDataViewQuery.VALUE);
    final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon1);
    Resources res = mActivity.getResources();

    ////  Axx = Auto-On or Auto-Off
    ////  OFF = Manual Off
    ////  ON = Manual On

    if (val.equalsIgnoreCase("AON")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.on));
        spinner.setSelection(0);
    } else if (val.equalsIgnoreCase("AOF")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.off));
        spinner.setSelection(0);
    } else if (val.equalsIgnoreCase("OFF")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.off));
        spinner.setSelection(1);
    } else if (val.equalsIgnoreCase("ON")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.on));
        spinner.setSelection(2);
    } else {
        iconView.setImageDrawable(new ColorDrawable(Color.BLUE));
    }
}

From source file:com.example.android.wizardpager.wizard.ui.ProfessorCityFromFragment.java

private void resetSpinner(Spinner spinner) {
    if (spinner.getAdapter() != null && spinner.getAdapter().getCount() > 0) {
        spinner.setAdapter(null);
    }//from  ww  w .  j ava 2 s  .c o m
}

From source file:com.google.mcommerce.sample.android.chapter09.googleMap.LayersDemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c09_layers_demo);
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    Spinner spinner = (Spinner) findViewById(R.id.layers_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.layers_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    spinner.setOnItemSelectedListener(this);
    setUpMapIfNeeded();//from ww  w  .j  a  v  a 2s.c  o  m
}

From source file:de.azapps.mirakel.settings.model_settings.special_list.dialogfragments.EditDialogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
        @Nullable final Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.special_lists_edit_dialog_fragment, null);
    final ArrayAdapter<CharSequence> spinnerArrayAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.special_lists_filter_type, android.R.layout.simple_spinner_dropdown_item);
    final Spinner spinner = (Spinner) rootView.findViewById(R.id.property_spinner);
    spinner.setAdapter(spinnerArrayAdapter);
    spinner.setOnItemSelectedListener(this);
    spinner.setSelection(propertyToType(property), false);
    handleNewFragment(propertyToType(property));
    final Button ok = (Button) rootView.findViewById(R.id.saveButton);
    ok.setOnClickListener(this);
    ((LinearLayout) rootView).setShowDividers(LinearLayout.SHOW_DIVIDER_END);
    return rootView;
}

From source file:com.esri.arcgisruntime.sample.blendrenderer.ParametersDialogFragment.java

/**
 * Builds parameter dialog with values pulled through from MainActivity.
 *
 * @param savedInstanceState/*  ww w . j ava 2 s .co m*/
 * @return create parameter dialog box
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    Bundle blendParameters = getArguments();
    if (blendParameters != null) {
        mAltitude = blendParameters.getInt("altitude");
        mAzimuth = blendParameters.getInt("azimuth");
        mSlopeType = (SlopeType) blendParameters.getSerializable("slope_type");
        mColorRampType = (ColorRamp.PresetType) blendParameters.getSerializable("color_ramp_type");
    }

    final AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext());
    @SuppressLint("InflateParams")
    View dialogView = inflater.inflate(R.layout.dialog_box, null);
    paramDialog.setView(dialogView);
    paramDialog.setTitle(R.string.dialog_title);
    paramDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });
    paramDialog.setPositiveButton("Render", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            ParametersListener activity = (ParametersListener) getActivity();
            activity.returnParameters(mAltitude, mAzimuth, mSlopeType, mColorRampType);
        }
    });

    mCurrAltitudeTextView = (TextView) dialogView.findViewById(R.id.curr_altitude_text);
    SeekBar altitudeSeekBar = (SeekBar) dialogView.findViewById(R.id.altitude_seek_bar);
    altitudeSeekBar.setMax(90); //altitude is restricted to 0 - 90
    //set initial altitude value
    updateAltitudeSeekBar(altitudeSeekBar);
    altitudeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAltitude = progress;
            updateAltitudeSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    mCurrAzimuthTextView = (TextView) dialogView.findViewById(R.id.curr_azimuth_text);
    SeekBar azimuthSeekBar = (SeekBar) dialogView.findViewById(R.id.azimuth_seek_bar);
    azimuthSeekBar.setMax(360); //azimuth measured in degrees 0 - 360
    //set initial azimuth value
    updateAzimuthSeekBar(azimuthSeekBar);
    azimuthSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAzimuth = progress;
            updateAzimuthSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    List<String> slopeTypeArray = new ArrayList<>();
    slopeTypeArray.add("None"); //ordinals:0
    slopeTypeArray.add("Degree"); //1
    slopeTypeArray.add("Percent rise"); //2
    slopeTypeArray.add("Scaled"); //3

    ArrayAdapter<String> slopeTypeSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_view,
            slopeTypeArray);

    Spinner slopeTypeSpinner = (Spinner) dialogView.findViewById(R.id.slope_type_spinner);
    slopeTypeSpinner.setAdapter(slopeTypeSpinnerAdapter);
    slopeTypeSpinner.setSelection(mSlopeType.ordinal());
    slopeTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mSlopeType = SlopeType.NONE;
                break;
            case 1:
                mSlopeType = SlopeType.DEGREE;
                break;
            case 2:
                mSlopeType = SlopeType.PERCENT_RISE;
                break;
            case 3:
                mSlopeType = SlopeType.SCALED;
                break;
            }
        }

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

    List<String> colorRampTypeArray = new ArrayList<>();
    colorRampTypeArray.add("None"); //ordinals:0
    colorRampTypeArray.add("Elevation"); //1
    colorRampTypeArray.add("DEM screen"); //2
    colorRampTypeArray.add("DEM light"); //3

    ArrayAdapter<String> colorRampSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_view,
            colorRampTypeArray);

    Spinner colorRampSpinner = (Spinner) dialogView.findViewById(R.id.color_ramp_spinner);
    colorRampSpinner.setAdapter(colorRampSpinnerAdapter);
    colorRampSpinner.setSelection(mColorRampType.ordinal());
    colorRampSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mColorRampType = ColorRamp.PresetType.NONE;
                break;
            case 1:
                mColorRampType = ColorRamp.PresetType.ELEVATION;
                break;
            case 2:
                mColorRampType = ColorRamp.PresetType.DEM_SCREEN;
                break;
            case 3:
                mColorRampType = ColorRamp.PresetType.DEM_LIGHT;
                break;
            }
        }

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

    return paramDialog.create();
}

From source file:com.cyrilmottier.android.polaris2demo.LayersDemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layers_demo);

    Spinner spinner = (Spinner) findViewById(R.id.layers_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.layers_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    mTrafficCheckbox = (CheckBox) findViewById(R.id.traffic);
    mMyLocationCheckbox = (CheckBox) findViewById(R.id.my_location);

    setUpMapIfNeeded();//from   w  ww. j  a  v a2s .  c  om
}

From source file:at.wada811.imageslider.DebugFragment.java

private void initDuration(Spinner durationSpinner) {
    List<String> asList = Arrays.asList(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" });
    final ArrayList<String> durations = new ArrayList<String>(asList);
    durationSpinner
            .setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.layout_spinner, R.id.item, durations));
    durationSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override/*  www . j a v  a 2  s.  c om*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String duration = durations.get(position);
            mCallback.setDuration(Integer.valueOf(duration) * 1000);
        }

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

        }
    });
}

From source file:com.simplechatclient.android.LoginFragment.java

public void myStart() {

    Config current_config = new Config(context);
    List<DatabaseProfile> profiles = current_config.getProfiles();

    profiles_list = new ArrayList<String>();
    for (DatabaseProfile profile : profiles) {
        profiles_list.add(profile.getNick());
    }//  ww  w .  j a  va  2 s. com

    Button login = (Button) view.findViewById(R.id.button_login);
    Spinner spinner = (Spinner) view.findViewById(R.id.spinnerNick);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,
            profiles_list);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    String nick = Settings.getInstance().get("nick");
    int default_position = profiles_list.indexOf(nick);
    if (default_position != -1)
        spinner.setSelection(default_position);

    spinner.setOnItemSelectedListener(spinnerListener);
    login.setOnClickListener(this);
}