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:org.droidpres.activity.TransferActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.transfer);/*from w  w  w .j a v  a  2 s .co  m*/

    cf = SetupRootActivity.getCurrencyFormat(this);

    mBtExport = (Button) findViewById(R.id.btExport);
    mBtImport = (Button) findViewById(R.id.btImport);
    mTvTrLog = (TextView) findViewById(R.id.tvTransferLog);
    mSpNetType = (Spinner) findViewById(R.id.spNetType);

    mBtImport.setOnClickListener(this);
    mBtExport.setOnClickListener(this);

    mDataBase = DB.get().getWritableDatabase();

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.itemNetType,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpNetType.setAdapter(adapter);

    mAgentId = Integer.parseInt(SetupRootActivity.getAgentID(this));
}

From source file:com.anton.gavel.GavelMain.java

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

    setContentView(R.layout.activity_gavel_main);

    // set up edit text input style for complaints (multiline, capitalize sentences)
    EditText edit = (EditText) findViewById(R.id.complaint_body);
    edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
            | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    // set up cities spinner
    Spinner citiesSpinner = (Spinner) findViewById(R.id.cities_spinner);
    ArrayAdapter<CharSequence> citiesAdapter = ArrayAdapter.createFromResource(this, R.array.cities,
            android.R.layout.simple_spinner_item);
    citiesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    citiesSpinner.setAdapter(citiesAdapter);

    // set up complaints map
    List<String> standardComplaints = this.getStandardComplaints();
    List<String> complaintSubmitValues = this.getComplaintSubmitValues();

    Iterator<String> standard = standardComplaints.iterator();
    Iterator<String> submit = complaintSubmitValues.iterator();
    complaintsMap = new HashMap<String, String>();
    //standard.next(); submit.next(); //skip the first item 'select a complaint'
    while (standard.hasNext() && submit.hasNext())
        complaintsMap.put(standard.next().toString(), submit.next().toString());

    // set up complaint spinner
    List<String> complaints_list = this.getStandardComplaints();
    complaintSpinner = (Spinner) findViewById(R.id.complaint_spinner);
    complaintsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
            complaints_list);//w ww  . j  a  va  2 s . c  o m
    complaintsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    complaintSpinner.setAdapter(complaintsAdapter);
    complaintSpinner.setOnItemSelectedListener(this);
    complaintSpinner.setOnItemLongClickListener(this);// this doesn't actually work yet bc not supported by API - events don't get fired

    //attach location listener to button
    findViewById(R.id.location_button).setOnClickListener(this);

    // make link in disclaimer clickable
    TextView disclaimer = (TextView) findViewById(R.id.disclaimer_textview);
    disclaimer.setMovementMethod(LinkMovementMethod.getInstance());

    // check &or load shared preferences to populate saved personal information
    mPersonalInfo = new PersonalInfo();
    SharedPreferences preferences = getPreferences(MODE_PRIVATE);
    mPersonalInfo.loadFromPreferences(preferences);

    // suppress keyboard
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // set complaint location to multiline for large layouts
    if (findViewById(R.id.layout_large_land) != null || findViewById(R.id.layout_large) != null) {
        ((EditText) findViewById(R.id.complaint_address)).setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    }

}

From source file:com.vaquerosisd.projectmanager.NewTask.java

private void setSpinner(String spinnerFileName, ArrayAdapter<CharSequence> spinnerAdapter,
        Spinner spinnerObject, boolean sort) {
    String spinnerItems = fO.readFile(spinnerFileName);
    ArrayList<String> spinnerItemsArray = fO.convertToStringList(spinnerItems);
    if (sort)//from  w  w  w.ja va2  s. c om
        Collections.sort(spinnerItemsArray.subList(0, spinnerItemsArray.size()));

    //Set the adapter for the status spinner 
    spinnerAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerAdapter.addAll(spinnerItemsArray);
    spinnerObject.setAdapter(spinnerAdapter);
}

From source file:de.qspool.clementineremote.ui.fragments.PlaylistFragment.java

private void updatePlaylistSpinner() {
    List<CharSequence> arrayList = new ArrayList<>();
    for (int i = 0; i < mPlaylists.size(); i++) {
        arrayList.add(mPlaylists.get(i).getName());
    }/* w  w w  .ja v  a2s .  com*/

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(),
            android.R.layout.simple_spinner_item, arrayList);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mPlaylistsSpinner.setAdapter(adapter);
}

From source file:eu.trentorise.smartcampus.communicator.fragments.messages.AbstractMessageListFragment.java

@SuppressWarnings("unchecked")
protected void setupSelectors() {
    if (hasLabelSelector()) {
        if (isLabelSelectorEnabled()) {
            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item);
            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            final Spinner labelFilter = (Spinner) getView().findViewById(R.id.messages_spinner_labels);
            labelFilter.setAdapter(dataAdapter);
            for (String n : CommunicatorHelper.getLabelsForSelector()) {
                ((ArrayAdapter<String>) labelFilter.getAdapter()).add(n);
            }//from  w  ww  .jav  a2 s.c om

            labelFilter.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    if (position == 0 && filter.getLabelId() == null)
                        return;
                    LabelObject selected = null;
                    try {
                        String selectedString = (String) labelFilter.getAdapter().getItem(position);
                        selected = CommunicatorHelper.getLabelByName(selectedString);

                        if (selected != null) {
                            if (selected.getId().equals(filter.getLabelId()))
                                return;
                            filter.setLabelId(selected.getId());
                        } else
                            filter.setLabelId(null);
                    } catch (Exception e) {
                        labelFilter.setSelection(0);
                    }
                    updateMessageList();
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                }
            });
        } else {
            getView().findViewById(R.id.messages_spinner_labels).setEnabled(false);
        }
    } else {
        ((LinearLayout) getView().findViewById(R.id.messages_filters))
                .removeView(getView().findViewById(R.id.messages_spinner_labels));

    }

}

From source file:com.z299studio.pb.EditFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mApp == null || mApp.getAccountManager() == null) {
        return null;
    }//from   ww  w .  j  a  v a 2  s  . c om
    View rootView = inflater.inflate(R.layout.fragment_edit, container, false);
    mContainer = (LinearLayout) rootView.findViewById(android.R.id.list);
    View footer = inflater.inflate(R.layout.add_field, container, false);
    footer.setOnClickListener(this);
    mNameEditText = (EditText) rootView.findViewById(android.R.id.title);
    mScroll = (PbScrollView) rootView.findViewById(R.id.scroll);
    mNameEditText.addTextChangedListener(this);
    mToolbarContainer = rootView.findViewById(R.id.toolbar_container);
    if (mToolbarContainer != null) {
        mHeader = rootView.findViewById(R.id.header);
        mScroll.setPbScrollListener(this);
    }
    setupToolbar(rootView);
    mCategorySpinner = (Spinner) rootView.findViewById(R.id.category);
    if (mAccountId >= 0) {
        mDummyAccount = mApp.getAccountManager().getAccountById(mAccountId).clone();
        mName = mDummyAccount.getAccountName();
    } else {
        mDummyAccount = getEntryList();
        mName = "";
    }
    int spinnerLayout = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN
            ? android.R.layout.simple_spinner_dropdown_item
            : R.layout.spinner_dropdown;
    mTypeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.field_types,
            android.R.layout.simple_spinner_dropdown_item);
    mTypeAdapter.setDropDownViewResource(spinnerLayout);
    mEntries = new ArrayList<>();
    mDeleteView = (ImageView) inflater.inflate(R.layout.delete_field, container, false);
    int pos = 0;
    for (Entry e : mDummyAccount.getEntryList()) {
        onAddField(e, pos++);
    }
    mContainer.addView(footer);
    mContainer.addView(mDeleteView);
    mDeleteView.setOnDragListener(mDragListener);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_spinner_dropdown_item, mApp.getSortedCategoryNames());
    spinnerAdapter.setDropDownViewResource(spinnerLayout);
    mCategorySpinner.setAdapter(spinnerAdapter);
    mCategorySpinner.setOnItemSelectedListener(this);
    View top = rootView.findViewById(R.id.top_frame);
    if (top != null) {
        top.setOnClickListener(this);
    }
    return rootView;
}

From source file:com.ksksue.app.ftdi_uart.MainActivity.java

private void makeSpinner(ArrayAdapter<String> dataAdapter) {
    spinner = (Spinner) findViewById(R.id.spinner);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);/*from  ww  w .  jav a2s. c  o  m*/
}

From source file:com.google.android.gms.samples.vision.ocrreader.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_main_test);
    serviceDB = new ServiceDB(this);
    MyMeter = new Meter(this);
    writeArabic = (TextView) findViewById(R.id.writeArabic);
    MeterRdg = (EditText) findViewById(R.id.MeterRdg);
    MeterRdg.setVisibility(View.GONE);
    writeArabic.setVisibility(View.GONE);
    ocrDetect = 0;/*from   w ww  .  j a  v  a 2s.  com*/
    ocrFinal = "";
    RecordRdg = (Button) findViewById(R.id.read_text);
    Description = (EditText) findViewById(R.id.description);
    statusMessage = (TextView) findViewById(R.id.status_message);
    textValue = (TextView) findViewById(R.id.text_value);
    customerName = (TextView) findViewById(R.id.cst_name);
    editText = (EditText) findViewById(R.id.editText);
    send = (Button) findViewById(R.id.button2);
    ok = (Button) findViewById(R.id.button3);
    autoFocus = (CompoundButton) findViewById(R.id.auto_focus);
    useFlash = (CompoundButton) findViewById(R.id.use_flash);
    meter1 = (CheckBox) findViewById(R.id.checkBox);
    meter2 = (CheckBox) findViewById(R.id.checkBox2);
    MeterStatus = getResources().getStringArray(R.array.meter_status_array);
    MeterTypes = getResources().getStringArray(R.array.meter_type_array);
    meterType = (TextView) findViewById(R.id.meterType);
    meterStatus = (Spinner) findViewById(R.id.meterStatus);
    editRDG = (EditText) findViewById(R.id.editRDG);
    //        meter1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    //            @Override
    //            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    //                if (meter1.isChecked()) {
    //                    meter2.setChecked(false);
    //                } else {
    //                    meter2.setChecked(true);
    //                }
    //            }
    //        });
    //        meter2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    //            @Override
    //            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    //                if (meter2.isChecked()) {
    //                    meter1.setChecked(false);
    //                } else {
    //                    meter1.setChecked(true);
    //                }
    //            }
    //        });
    ////        findViewById(R.id.read_text).setOnClickListener(this);
    customerCode = (TextView) findViewById(R.id.editText2);
    _getLocation();
    spinner = (Spinner) findViewById(R.id.spinner);
    Cursor cursor = serviceDB.FetchGPS(lat, lon, MainActivity.GPS_RADIUS);
    final ArrayList<Customers> myCustomersList = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                Customers customers = new Customers(cursor.getString(2));
                customers.setCst_ParCode(cursor.getString(1));
                customers.setCst_X(cursor.getString(3));
                customers.setCst_Y(cursor.getString(4));
                customers.setMeter_status(cursor.getInt(5));
                customers.setMeter_type(cursor.getInt(6));
                myCustomersList.add(customers);
            } while (cursor.moveToNext());
        }
        final List<String> customersName = new ArrayList<>();
        for (int i = 0; i < myCustomersList.size(); i++) {
            customersName.add(myCustomersList.get(i).getCst_Name());
        }
        ListView listView = (ListView) findViewById(R.id.CustomerList);
        CustomerListAdapter customerListAdapter = new CustomerListAdapter(myCustomersList, this);
        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, customersName); //selected item will look like a spinner set from XML
        spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        meterStatus.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            }

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

            }
        });

        listView.setAdapter(customerListAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                customerName.setText(myCustomersList.get(position).getCst_Name());
                SelectedCustomer = myCustomersList.get(position);
                meterType.setText(MyMeter.getMeterTypeFromInt(SelectedCustomer.getMeter_type()));
                meterStatus.setSelection(
                        Integer.parseInt(MyMeter.meterStatusValues[SelectedCustomer.getMeter_status()]));
                if (!MyMeter.isEditableStatus(SelectedCustomer.getMeter_status())) {
                    meterStatus.setEnabled(false);
                    RecordRdg.setEnabled(false);
                    send.setEnabled(false);
                } else {
                    meterStatus.setEnabled(true);
                    RecordRdg.setEnabled(true);
                    send.setEnabled(true);
                }

            }
        });

    }
}

From source file:com.digi.android.wva.fragments.EndpointOptionsDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (mConfig == null && savedInstanceState == null) {
        Log.e(TAG, "mConfig is null, not showing dialog!");
        return null;
    }/*from w  ww .  j a  va 2 s  .  c  o  m*/

    LayoutInflater inf = getActivity().getLayoutInflater();
    View v = inf.inflate(R.layout.dialog_endpoint_options, null);

    // Suppresses warnings, and ensures the layout exists.
    assert v != null;
    final TextView subIntervalTV = (TextView) v.findViewById(R.id.textView_interval);
    final TextView alarmInfoTV = (TextView) v.findViewById(R.id.alarm_info);
    final CheckBox subscribedCB = (CheckBox) v.findViewById(R.id.subscribedCheckbox);
    final CheckBox alarmCB = (CheckBox) v.findViewById(R.id.alarmCheckbox);
    final EditText subInterval = (EditText) v.findViewById(R.id.subscriptionInterval);
    final EditText alarmThreshold = (EditText) v.findViewById(R.id.alarmThreshold);
    final Spinner typeSpinner = (Spinner) v.findViewById(R.id.alarmTypeSpinner);
    final LinearLayout makeAlarmSection = (LinearLayout) v.findViewById(R.id.section_make_alarm);
    final LinearLayout showAlarmSection = (LinearLayout) v.findViewById(R.id.section_show_alarm);
    final CheckBox dcSendCB = (CheckBox) v.findViewById(R.id.dcPushCheckbox);

    String alarmInfo = "No alarm yet";
    boolean isSubscribed = false;
    String endpointName = "UNKNOWN";
    int sinterval = 10;
    boolean alarmCreated = false;
    double threshold = 0;
    int alarmtypeidx = 0;

    boolean isSendingToDC = false;

    if (savedInstanceState != null && savedInstanceState.containsKey("config")) {
        mConfig = savedInstanceState.getParcelable("config");
    }

    if (mConfig != null) {
        endpointName = mConfig.getEndpoint();
        alarmInfo = mConfig.getAlarmSummary();

        if (mConfig.getSubscriptionConfig() != null) {
            isSubscribed = mConfig.getSubscriptionConfig().isSubscribed();
            sinterval = mConfig.getSubscriptionConfig().getInterval();
            isSendingToDC = mConfig.shouldBePushedToDeviceCloud();
        } else {
            // Not subscribed; default interval value from preferences.
            String i = PreferenceManager.getDefaultSharedPreferences(getActivity())
                    .getString("pref_default_interval", "0");
            try {
                sinterval = Integer.parseInt(i);
            } catch (NumberFormatException e) {
                Log.d(TAG, "Failed to parse default interval from preferences: " + i);
                sinterval = 0;
            }
        }

        if (mConfig.getAlarmConfig() != null) {
            alarmCreated = mConfig.getAlarmConfig().isCreated();
            threshold = mConfig.getAlarmConfig().getThreshold();
            String typestr = AlarmType.makeString(mConfig.getAlarmConfig().getType());
            for (int i = 0; i < alarmTypes.length; i++) {
                if (alarmTypes[i].toLowerCase(Locale.US).equals(typestr))
                    alarmtypeidx = i;
            }
        }
    }

    // Set up event listeners on EditText and CheckBox items

    subscribedCB.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            subInterval.setEnabled(isChecked);
            subIntervalTV.setEnabled(isChecked);
        }
    });

    alarmCB.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            typeSpinner.setEnabled(isChecked);
            alarmThreshold.setEnabled(false);
            // If type spinner is set to Change, we want threshold disabled again
            if (isChecked) {
                alarmThreshold.setEnabled(!shouldDisableAlarmThreshold(typeSpinner.getSelectedItemPosition()));
            }
        }
    });

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            if (alarmCB.isChecked() && shouldDisableAlarmThreshold(position))
                alarmThreshold.setEnabled(false);
            else if (!alarmCB.isChecked())
                alarmThreshold.setEnabled(false);
            else
                alarmThreshold.setEnabled(true);
        }

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

    subIntervalTV.setEnabled(false);
    subInterval.setEnabled(false);
    alarmThreshold.setEnabled(false);
    typeSpinner.setEnabled(false);
    alarmInfoTV.setText(alarmInfo);

    // Click checkboxes, show data depending on if subscription or alarm
    // has been added already
    if (isSubscribed)
        subscribedCB.performClick();
    if (alarmCreated) {
        showAlarmSection.setVisibility(View.VISIBLE);
        makeAlarmSection.setVisibility(View.GONE);
        alarmCB.setText("Remove alarm");
    } else {
        makeAlarmSection.setVisibility(View.VISIBLE);
        showAlarmSection.setVisibility(View.GONE);
        alarmCB.setText("Create alarm");
    }

    dcSendCB.setChecked(isSendingToDC);

    subInterval.setText(Integer.toString(sinterval));

    alarmThreshold.setText(Double.toString(threshold));

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alarm_types,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    typeSpinner.setAdapter(adapter);
    typeSpinner.setSelection(alarmtypeidx);

    DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            // Fetch the EndpointsAdapter's configuration for this endpoint.
            // (We might have gotten mConfig from the saved instance bundle)
            EndpointConfiguration cfg = EndpointsAdapter.getInstance()
                    .findEndpointConfiguration(mConfig.getEndpoint());

            // Set whether this endpoint's data should be pushed to Device Cloud
            if (cfg != null) {
                cfg.setPushToDeviceCloud(dcSendCB.isChecked());
            }

            // Handle (un)subscribing

            if (isUnsubscribing(subscribedCB.isChecked())) {
                unsubscribe(mConfig.getEndpoint());
            } else if (subscribedCB.isChecked()) {
                if (handleMakingSubscription(subInterval)) {
                    // Subscription was successful... most likely.
                    Log.d(TAG, "Probably subscribed to endpoint.");
                } else {
                    // Invalid interval.
                    Toast.makeText(getActivity(),
                            getString(R.string.configure_endpoints_toast_invalid_sub_interval),
                            Toast.LENGTH_SHORT).show();
                }
            }

            // Handle adding/removing alarm as necessary

            if (isRemovingAlarm(alarmCB.isChecked())) {
                removeAlarm(mConfig.getEndpoint(), mConfig.getAlarmConfig().getType());
            } else if (alarmCB.isChecked()) {
                Editable thresholdText = alarmThreshold.getText();
                String thresholdString;
                if (thresholdText == null)
                    thresholdString = "";
                else
                    thresholdString = thresholdText.toString();

                double threshold;
                try {
                    threshold = Double.parseDouble(thresholdString);
                } catch (NumberFormatException e) {
                    Toast.makeText(getActivity(), getString(R.string.configure_endpoints_invalid_threshold),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                int alarmidx = typeSpinner.getSelectedItemPosition();
                if (alarmidx == -1) {
                    // But... how?
                    Log.wtf(TAG, "alarm type index -1 ?");
                    return;
                }
                String type = alarmTypes[alarmidx];
                AlarmType atype = AlarmType.fromString(type);

                createAlarm(mConfig.getEndpoint(), atype, threshold);
            }

            dialog.dismiss();
        }
    };

    return new AlertDialog.Builder(getActivity()).setView(v).setTitle("Endpoint: " + endpointName)
            .setPositiveButton("Save", clickListener)
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Cancel means just dismiss the dialog.
                    dialog.dismiss();
                }
            }).create();
}

From source file:com.xengar.android.englishverbs.ui.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the verb.
 *//*from w  w w. j  ava 2s  .c o m*/
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
    mRegularSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mRegularSpinner.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.type_regular))) {
                    mRegular = VerbEntry.REGULAR;
                } else {
                    mRegular = VerbEntry.IRREGULAR;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mRegular = VerbEntry.REGULAR;
        }
    });
}