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.example.community_list_post.posting.CurrentFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Create the spiiner drop down menu
    Spinner dropdown = (Spinner) getView().findViewById(R.id.spinner_current);
    String[] items = new String[] { "General", "Events", "Crime", "Missing", "Market", "Jobs", "Specials" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            items);/* w w  w  .j ava2  s .  co m*/
    dropdown.setAdapter(adapter);

    EditText postCurrent = (EditText) getView().findViewById(R.id.post_current);

    Button current_button = (Button) getView().findViewById(R.id.post_current_button);
    //Create the mapview        
}

From source file:fr.eoit.activity.fragment.blueprint.RequiredDecryptorFragment.java

@Override
public void onLoadFinished(Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor)) {
        String[] from = new String[] { Item.COLUMN_NAME_NAME, "decryptorDesc" };
        int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

        MatrixCursor decryptorCursor = new MatrixCursor(
                new String[] { Item._ID, Item.COLUMN_NAME_NAME, "decryptorDesc" });
        DbUtil.addRowToMatrixCursor(decryptorCursor, 0L, "None", "");

        cursor.moveToFirst();/*w ww . jav  a  2  s  .  c  om*/
        int selectedItem = 0;
        while (!cursor.isAfterLast()) {
            long itemId = cursor.getLong(cursor.getColumnIndexOrThrow(Item._ID));
            DbUtil.addRowToMatrixCursor(decryptorCursor, itemId,
                    cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)),
                    getDecryptorDescription(DecryptorUtil.getDecryptorBonuses(itemId),
                            getActivity().getResources()));

            if (itemId == decryptorId) {
                selectedItem = cursor.getPosition() + 1;
            }

            cursor.moveToNext();
        }

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(),
                android.R.layout.simple_spinner_item, decryptorCursor, from, to,
                SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        Spinner spinner = (Spinner) getActivity().findViewById(R.id.DECRYPTOR_SPINNER);
        adapter.setDropDownViewResource(R.layout.decryptor_drop_down_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new SpinnerDecryptorOnItemSelectedListener());
        spinner.setSelection(selectedItem);
    }
}

From source file:net.ustyugov.jtalk.activity.muc.MucUsers.java

private void showDialog() {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.set_affiliate_dialog,
            (ViewGroup) findViewById(R.id.set_affiliate_linear));

    final EditText jidEdit = (EditText) layout.findViewById(R.id.jid);
    jidEdit.setEnabled(true);//from   w ww.j av  a2 s. c  o m
    jidEdit.setText(editedJid);

    String[] affiliations = new String[4];
    affiliations[0] = "owner";
    affiliations[1] = "admin";
    affiliations[2] = "member";
    affiliations[3] = "outcast";

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            affiliations);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final Spinner spinner = (Spinner) layout.findViewById(R.id.spinner);
    spinner.setAdapter(arrayAdapter);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    builder.setTitle(getString(R.string.Edit));
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String aff = (String) spinner.getSelectedItem();

            MUCAdmin.Item i = new MUCAdmin.Item(aff, null);
            if (newJid)
                i.setJid(jidEdit.getText().toString());
            else
                i.setJid(editedJid);

            MUCAdmin admin = new MUCAdmin();
            admin.setType(IQ.Type.SET);
            admin.setTo(muc.getRoom());
            admin.addItem(i);

            JTalkService.getInstance().getConnection(account).sendPacket(admin);
            update();
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.create().show();
}

From source file:uk.org.freeflight.wifefinder.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Create cursor adaptor for the spinner control
    Cursor cursor = db.makeCursor();
    String[] from = { WifeFinderDb.DbContract.AircraftTable.COLUMN_NAME_AIRCRAFT_REG };
    int[] to = { android.R.id.text1 };
    aircraftCursorAdapter = new SimpleCursorAdapter(this, R.layout.spinner_item, cursor, from, to, 0);
    aircraftCursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // Spinner setup
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem item = menu.findItem(R.id.aircraft_spinner);
    Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);
    spinner.setAdapter(aircraftCursorAdapter);
    setSpinnerItemById(spinner, id);//from ww  w  .j a  v a2s .c o m
    spinner.setOnItemSelectedListener(this);

    return true;
}

From source file:org.eyeseetea.malariacare.fragments.PlannedFragment.java

private void prepareUI() {
    this.adapter = new PlannedAdapter(plannedItems, getActivity());
    this.setListAdapter(adapter);

    Spinner programSpinner = (Spinner) getActivity().findViewById(R.id.dashboard_planning_program);
    //Populate Program View DDL
    programList.add(0, programDefaultOption);
    programSpinner.setAdapter(new FilterProgramArrayAdapter(getActivity(), programList));
    //Apply filter to listview
    programSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  w  w  w  . j av a 2  s  .  c om
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Spinner spinner = ((Spinner) parent);
            Program selectedProgram = position == 0 ? null : (Program) spinner.getItemAtPosition(position);
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            adapter.applyFilter(selectedProgram);
        }

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

        }
    });

}

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

@Override
protected void onPostExecute(Boolean result) {
    mDialog.dismiss();/* w  w w. j av  a  2s.com*/

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

    } else {

        ListView lv = (ListView) rootView.findViewById(R.id.listView1);
        ArrayList<String> dir = new ArrayList<String>();

        //File sdCardRoot = Environment.getExternalStorageDirectory();
        final File MusicDir = new File(LOCAL_MUSIC_DIR);

        for (File f : MusicDir.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) {

            showToast(mErrorMsg);
        } else {
            // Couldn't download it, so show an error
            showToast(mErrorMsg);
        }
    }
}

From source file:com.gsma.rcs.provisioning.local.LoggerProvisioning.java

@Override
public void displayRcsSettings() {
    if (sLogger.isActivated()) {
        sLogger.debug("displayRcsSettings");
    }//from   w w w .j  a v a2  s . c o m
    mHelper.setBoolCheckBox(R.id.TraceActivated, RcsSettingsData.TRACE_ACTIVATED);
    mHelper.setBoolCheckBox(R.id.SipTraceActivated, RcsSettingsData.SIP_TRACE_ACTIVATED);
    mHelper.setBoolCheckBox(R.id.MediaTraceActivated, RcsSettingsData.MEDIA_TRACE_ACTIVATED);
    mHelper.setStringEditText(R.id.SipTraceFile, RcsSettingsData.SIP_TRACE_FILE);

    Spinner spinner = (Spinner) mRootView.findViewById(R.id.TraceLevel);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item,
            TRACE_LEVEL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(sRcsSettings.getTraceLevel());
}

From source file:br.com.bioscada.apps.biotracks.fragments.StatsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    handler = new Handler();

    Spinner activityTypeIcon = (Spinner) getView().findViewById(R.id.stats_activity_type_icon);
    activityTypeIcon.setAdapter(TrackIconUtils.getIconSpinnerAdapter(getActivity(), ""));
    activityTypeIcon.setOnTouchListener(new View.OnTouchListener() {
        @Override// w w w  .  j  ava 2  s. c  o m
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                ((TrackDetailActivity) getActivity()).chooseActivityType(category);
            }
            return true;
        }
    });
    activityTypeIcon.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
                ((TrackDetailActivity) getActivity()).chooseActivityType(category);
            }
            return true;
        }
    });
}

From source file:me.willeponken.opendoor.FirstRunSlide.java

@Nullable
@Override//w  w w. j a v  a 2 s .c  o m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(layoutResId, container, false);
    if (R.layout.fragment_initial1 == layoutResId) {
        editText = (EditText) v.findViewById(R.id.defaultNumber);
        Spinner spinner = (Spinner) v.findViewById(R.id.lab_spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
                R.array.lab_spinner_titles, R.layout.custom_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.select_dialog_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);
    }
    return v;
}

From source file:org.firebears.scouting2846.TeamDetailFragment.java

private void initScoutingSpinner() {
    ArrayList<String> items = new ArrayList<String>();
    items.add(getActivity().getString(R.string.pit));
    for (int i = 1; i <= 100; i++)
        items.add("Qm" + i);
    Spinner sp = (Spinner) root_view.findViewById(R.id.scout_spn);
    ArrayAdapter<String> spad = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            items);//from  ww w. ja v a  2  s.c  om
    spad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp.setAdapter(spad);
}