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:eu.power_switch.gui.fragment.alarm_clock.SleepAsAndroidFragment.java

@Override
public void onCreateViewEvent(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_sleep_as_android, container, false);

    setHasOptionsMenu(true);/*from  w  w  w .  ja v  a2 s  .co m*/

    final RecyclerViewFragment recyclerViewFragment = this;

    Switch switchOnOff = (Switch) rootView.findViewById(R.id.switch_on_off);
    switchOnOff.setChecked(SmartphonePreferencesHandler.getSleepAsAndroidEnabled());
    switchOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (buttonView.isPressed()) {
                SmartphonePreferencesHandler.setSleepAsAndroidEnabled(isChecked);
            }
        }
    });

    layout_installed = (LinearLayout) rootView.findViewById(R.id.layout_installed);
    layout_not_installed = (LinearLayout) rootView.findViewById(R.id.layout_not_installed);

    IconicsImageView getFromPlayStore = (IconicsImageView) rootView.findViewById(R.id.get_from_play_store);
    getFromPlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SleepAsAndroidHelper.openPlayStorePage(getActivity());
        }
    });

    spinnerEventType = (Spinner) rootView.findViewById(R.id.spinner_sleep_as_android_event);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
            R.array.sleep_as_android_event_names, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerEventType.setAdapter(adapter);
    SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() {
        @Override
        public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) {
            updateUI();
        }
    };
    spinnerEventType.setOnItemSelectedListener(spinnerInteractionListener);
    spinnerEventType.setOnTouchListener(spinnerInteractionListener);

    recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    recyclerViewAdapter = new ActionRecyclerViewAdapter(getContext(), actions);
    recyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View itemView, final int position) {
            new AlertDialog.Builder(getContext()).setTitle(R.string.delete).setMessage(R.string.are_you_sure)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                actions.remove(position);
                                DatabaseHandler.setAlarmActions(SLEEP_AS_ANDROID_ALARM_EVENT
                                        .getById(spinnerEventType.getSelectedItemPosition()), actions);
                                StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(),
                                        R.string.action_removed, Snackbar.LENGTH_LONG);
                            } catch (Exception e) {
                                StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(),
                                        e);
                            }

                            recyclerViewAdapter.notifyDataSetChanged();
                        }
                    }).setNeutralButton(android.R.string.cancel, null).show();
        }
    });
    recyclerViewActions.setAdapter(recyclerViewAdapter);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(),
            StaggeredGridLayoutManager.VERTICAL);
    recyclerViewActions.setLayoutManager(layoutManager);

    addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
    addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(),
            ContextCompat.getColor(getActivity(), android.R.color.white)));
    addActionFAB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AddSleepAsAndroidAlarmEventActionDialog addAlarmEventActionDialog = AddSleepAsAndroidAlarmEventActionDialog
                    .newInstance(spinnerEventType.getSelectedItemPosition());
            addAlarmEventActionDialog.setTargetFragment(recyclerViewFragment, 0);
            addAlarmEventActionDialog.show(getActivity().getSupportFragmentManager(), null);
        }
    });

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(this, "received intent: " + intent.getAction());

            if (LocalBroadcastConstants.INTENT_ALARM_EVENT_ACTION_ADDED.equals(intent.getAction())) {
                updateUI();
            } else {
                updateUI();
            }
        }
    };
}

From source file:com.example.android.viewpager.MondayFragment.java

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

    String[] arrayNorm = { "??", "??", "??",
            "??", "??", "???", "??",
            "??", "?", "??", "?",
            "?", "??", "?", "?",
            "?", "??", "??",
            "?", "?", "?",
            "?", "", "?", "", "",
            "?", "?", "??",
            "??", "??", "?", "",
            "?", "?", "?", "?",
            "?", "", "?", "?",
            "??", "??", "?",
            "?", "?", "?", "",
            "", "?", "?", "?",
            "??", "??", "", "?",
            "??", "?", "?", "?",
            "??", "?", "?", "?",
            "", "?", "", "?",
            "?", "?", "?", "?",
            "?", "", "", "?",
            "?", "?", "", "?",
            "?", "", "?", "?",
            "?", "?", "??", "?",
            "?", "?" };

    final String[] arraySokr = { "az", "sq", "am", "en", "ar", "hy", "af", "eu", "ba", "be", "bn", "bg", "bs",
            "cy", "hu", "vi", "ht", "gl", "nl", "mrj", "el", "ka", "gu", "da", "he", "yi", "id", "ga", "it",
            "is", "es", "kk", "kn", "ca", "ky", "zh", "ko", "xh", "la", "lv", "lt", "lb", "mg", "ms", "ml",
            "mt", "mk", "mi", "mr", "mhr", "mn", "de", "ne", "no", "pa", "pap", "fa", "pl", "pt", "ro", "ru",
            "ceb", "sr", "si", "sk", "sl", "sw", "su", "tg", "th", "tl", "ta", "tt", "te", "tr", "udm", "uz",
            "uk", "ur", "fi", "fr", "hi", "hr", "cs", "sv", "gd", "et", "eo", "jv", "ja" };

    spinner = (Spinner) view.findViewById(R.id.spinner_nav);
    spinner2 = (Spinner) view.findViewById(R.id.spinner_nav2);
    translatedTextTextView = (TextView) view.findViewById(R.id.textView);
    textToTranslateEditText = (EditText) view.findViewById(R.id.editText2);

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
            android.R.layout.simple_spinner_item, arrayNorm); //selected item will look like a spinner set from XML
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerArrayAdapter);
    spinner2.setAdapter(spinnerArrayAdapter);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View itemSelected, int selectedItemPosition,
                long selectedId) {
            int posNum = spinner.getSelectedItemPosition();
            l1 = arraySokr[posNum];//from   w w w .j  av a2s.  c o m
        }

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

    spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View itemSelected, int selectedItemPosition,
                long selectedId) {

            int posNum = spinner.getSelectedItemPosition();
            l2 = arraySokr[posNum];
        }

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

    textToTranslateEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //? ,    ?
            if (textToTranslateEditText.getText().toString().isEmpty()) {
                Toast.makeText(getActivity().getApplicationContext(),
                        " ? ? ", Toast.LENGTH_SHORT).show();
            } else {
                if (textToTranslateEditText.isFocused()) {
                    String text = textToTranslateEditText.getText().toString();

                    String language = l1 + "-" + l2;
                    new Task().execute(text, language);

                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            //TranslateWord translateWord = new TranslateWord(textToTranslateEditText.getText().toString(),translatedTextTextView.getText().toString(), R.drawable.off_fav, "en-ru");
            //myRef.push().setValue(translateWord);
        }
    });

    return view;

}

From source file:fabiogentile.powertutor.ui.UMLogger.java

/**
 * Called when the activity is first created.
 *///from w w w.  j  a  v  a 2  s  .co  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate: ");
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    serviceIntent = new Intent(this, UMLoggerService.class);
    conn = new CounterServiceConnection();

    SystemInfo.getInstance().setContext(getApplicationContext());

    setContentView(R.layout.main);
    ArrayAdapter<?> adapterxaxis = ArrayAdapter.createFromResource(this, R.array.xaxis,
            android.R.layout.simple_spinner_item);
    adapterxaxis.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    //If Marshmallow ask permission explicitly
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        askPermission();

    serviceStartButton = (Button) findViewById(R.id.servicestartbutton);
    appViewerButton = (Button) findViewById(R.id.appviewerbutton);
    sysViewerButton = (Button) findViewById(R.id.sysviewerbutton);
    helpButton = (Button) findViewById(R.id.helpbutton);

    serviceStartButton.setOnClickListener(serviceStartButtonListener);
    sysViewerButton.setOnClickListener(sysViewerButtonListener);
    appViewerButton.setOnClickListener(appViewerButtonListener);
    helpButton.setOnClickListener(helpButtonListener);

    if (counterService != null) {
        serviceStartButton.setText("Stop Profiler");
        appViewerButton.setEnabled(true);
        sysViewerButton.setEnabled(true);
    } else {
        serviceStartButton.setText("Start Profiler");
        appViewerButton.setEnabled(false);
        sysViewerButton.setEnabled(false);
    }
}

From source file:com.example.meetingapp.OptionsFragment.java

private void setupSpinners() {
    mCategoryAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.categories,
            android.R.layout.simple_spinner_item);
    mCategoryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCategorySpinner.setAdapter(mCategoryAdapter);

    ArrayAdapter<CharSequence> minPriceAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.prices,
            android.R.layout.simple_spinner_item);
    minPriceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMinPriceSpinner.setAdapter(minPriceAdapter);

    ArrayAdapter<CharSequence> maxPriceAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.prices,
            android.R.layout.simple_spinner_item);
    maxPriceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMaxPriceSpinner.setAdapter(maxPriceAdapter);

    /* set the default option to be "Very Expensive" */
    mMaxPriceSpinner.setSelection(mPriceOptions.length - 1);
}

From source file:com.bydavy.card.receipts.activities.ReceiptListActivity.java

private void setupActionBar() {
    final Context context = getSupportActionBar().getThemedContext();
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    final ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context,
            R.array.activity_receipt_list__navigation_list, R.layout.sherlock_spinner_item);
    list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
    getSupportActionBar().setListNavigationCallbacks(list, this);
}

From source file:com.example.android.gcncouponalert.app.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    //Spinner spinner = (Spinner) findViewById(R.id.coupons_spinner);
    MenuItem item = menu.findItem(R.id.coupons_spinner);
    Spinner spinner = (Spinner) item.getActionView();
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.coupon_filter_options,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);//from  w  w  w .  j a va  2s .com
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.d(LOG_TAG, " onItemSelected: " + position + "; " + id);
            CouponsFragment ff = (CouponsFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.fragment_forecast);
            if (null != ff) {
                ff.onSpinnerChanged(position);
            }
        }

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

            // sometimes you need nothing here
        }
    });
    //MenuItem item = menu.findItem(R.id.coupons_spinner);
    //Spinner spinner =(Spinner) item.getActionView();
    //setupSpinner(spinner);
    //String[] items={"All","Favorites"};
    //wrap the items in the Adapter
    //ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);
    //assign adapter to the Spinner
    //spinner.setAdapter(adapter);

    //MenuItem item = menu.findItem(R.id.coupons_spinner);
    //Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);
    //spinner.setAdapter(adapter); // set the adapter to provide layout of rows and content
    //s.setOnItemSelectedListener(onItemSelectedListener); // set the listener, to perform actions based on item selection
    return true;
}

From source file:com.example.amit.tellymoviebuzzz.ImdbFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from our cursor and populate the ListView.
    mForecastAdapter = new ImdbAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.imdbthisyear_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView1 = (ListView) rootView.findViewById(R.id.listview_imdbthisyear_movies);
    listView1.setAdapter(mForecastAdapter);

    final String[] str = { "Action", "Adventure", "Animation", "Comedy", "Crime", "Documentary", "Drama",
            "Family", "Fantasy", "Foreign", "History", "Horror", "Music", "Mystery", "Romance",
            "Science Fiction", "TV Movie", "Thriller", "War", "Western", "Others" };

    Spinner sp1 = (Spinner) rootView.findViewById(R.id.spinnerthisyear);
    //final Spinner sp2= (Spinner) findViewById(R.id.spinner2);

    ArrayAdapter<String> adp1 = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            str);//from  ww w.  j a  v a  2s  .com
    adp1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp1.setAdapter(adp1);

    sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            // TODO Auto-generated method stub
            // Toast.makeText(getBaseContext(),list.get(position), Toast.LENGTH_SHORT).show();

            String val = str[position];

            Bundle bund = new Bundle();
            bund.putString("choice", val);
            // bund.
            getLoaderManager().restartLoader(FORECAST_LOADER, bund, ImdbFragment.this);

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }

    });

    // Spinner spinner = (Spinner) rootView.findViewById(R.id.spinnerthisyear);

    /// String[] options = {"India","USA","UK"};

    // android.R.layout.support_simple_spinner_dropdown_item

    // We'll call our MainActivity
    listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                // String locationSetting = Utility.getPreferredLocation(getActivity());
                String movieSetting = "thisyear";
                //Utility.getPreferredMovie(getActivity());

                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                //               locationSetting, cursor.getLong(COL_WEATHER_DATE)
                //       ));
                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //         .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING)));

                Intent intent = new Intent(getActivity(), DetailActivity.class);
                // .setData(cursor.getString(ImdbFragment.COL_TMDBID));
                intent.putExtra("movieid", cursor.getString(ImdbFragment.COL_TMDBID));

                startActivity(intent);
            }
        }
    });
    return rootView;
}

From source file:com.example.amit.tellymoviebuzzz.ImdbUpcomingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from our cursor and populate the ListView.
    mForecastAdapter = new ImdbUpcomingAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.imdbupcoming_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_imdbupcoming_movies);
    listView.setAdapter(mForecastAdapter);

    final String[] str1 = { "Action", "Adventure", "Animation", "Comedy", "Crime", "Documentary", "Drama",
            "Family", "Fantasy", "Foreign", "History", "Horror", "Music", "Mystery", "Romance",
            "Science Fiction", "TV Movie", "Thriller", "War", "Western", "Others" };

    Spinner sp2 = (Spinner) rootView.findViewById(R.id.spinnerupcomingyear);
    //final Spinner sp2= (Spinner) findViewById(R.id.spinner2);

    ArrayAdapter<String> adp2 = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            str1);//from w w  w.j a va 2  s. c  o  m
    adp2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp2.setAdapter(adp2);

    sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            // TODO Auto-generated method stub
            // Toast.makeText(getBaseContext(),list.get(position), Toast.LENGTH_SHORT).show();

            String val = str1[position];

            Bundle bund = new Bundle();
            bund.putString("choice", val);
            // bund.
            getLoaderManager().restartLoader(FORECAST_LOADER, bund, ImdbUpcomingFragment.this);

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }

    });

    // Spinner spinner = (Spinner) rootView.findViewById(R.id.spinnerthisyear);

    /// String[] options = {"India","USA","UK"};

    // android.R.layout.support_simple_spinner_dropdown_item

    // We'll call our MainActivity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                // String locationSetting = Utility.getPreferredLocation(getActivity());
                String movieSetting = "thisyear";
                //Utility.getPreferredMovie(getActivity());

                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                //               locationSetting, cursor.getLong(COL_WEATHER_DATE)
                //       ));
                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //         .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING)));

                Intent intent = new Intent(getActivity(), DetailActivity.class);
                // .setData(cursor.getString(ImdbUpcomingFragment.COL_TMDBID));
                intent.putExtra("movieid", cursor.getString(ImdbUpcomingFragment.COL_TMDBID));

                startActivity(intent);
            }
        }
    });
    return rootView;
}

From source file:com.example.am.myapplication.ContactAdder.java

/**
 * Called when the activity is first created. Responsible for initializing the UI.
 *///from  w  ww . j  a  va 2 s. c om
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "Activity State: onCreate()");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contact_adder);

    // Obtain handles to UI objects
    mAccountSpinner = (Spinner) findViewById(R.id.accountSpinner);
    mContactNameEditText = (EditText) findViewById(R.id.contactNameEditText);
    mContactPhoneEditText = (EditText) findViewById(R.id.contactPhoneEditText);
    mContactEmailEditText = (EditText) findViewById(R.id.contactEmailEditText);
    mContactPhoneTypeSpinner = (Spinner) findViewById(R.id.contactPhoneTypeSpinner);
    mContactEmailTypeSpinner = (Spinner) findViewById(R.id.contactEmailTypeSpinner);
    mContactSaveButton = (Button) findViewById(R.id.contactSaveButton);

    // Prepare list of supported account types
    // Note: Other types are available in ContactsContract.CommonDataKinds
    //       Also, be aware that type IDs differ between Phone and Email, and MUST be computed
    //       separately.
    mContactPhoneTypes = new ArrayList<Integer>();
    mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_HOME);
    mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_WORK);
    mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
    mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_OTHER);
    mContactEmailTypes = new ArrayList<Integer>();
    mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_HOME);
    mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_WORK);
    mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_MOBILE);
    mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_OTHER);

    // Prepare model for account spinner
    mAccounts = new ArrayList<AccountData>();
    mAccountAdapter = new AccountAdapter(this, mAccounts);
    mAccountSpinner.setAdapter(mAccountAdapter);

    // Populate list of account types for phone
    ArrayAdapter<String> adapter;
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Iterator<Integer> iter;
    iter = mContactPhoneTypes.iterator();
    while (iter.hasNext()) {
        adapter.add(ContactsContract.CommonDataKinds.Phone
                .getTypeLabel(this.getResources(), iter.next(), getString(R.string.undefinedTypeLabel))
                .toString());
    }
    mContactPhoneTypeSpinner.setAdapter(adapter);
    mContactPhoneTypeSpinner.setPrompt(getString(R.string.selectLabel));

    // Populate list of account types for email
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    iter = mContactEmailTypes.iterator();
    while (iter.hasNext()) {
        adapter.add(ContactsContract.CommonDataKinds.Email
                .getTypeLabel(this.getResources(), iter.next(), getString(R.string.undefinedTypeLabel))
                .toString());
    }
    mContactEmailTypeSpinner.setAdapter(adapter);
    mContactEmailTypeSpinner.setPrompt(getString(R.string.selectLabel));

    // Prepare the system account manager. On registering the listener below, we also ask for
    // an initial callback to pre-populate the account list.
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);

    // Register handlers for UI elements
    mAccountSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long i) {
            updateAccountSelection();
        }

        public void onNothingSelected(AdapterView<?> parent) {
            // We don't need to worry about nothing being selected, since Spinners don't allow
            // this.
        }
    });
    mContactSaveButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onSaveButtonClicked();
        }
    });
}

From source file:com.forrestguice.suntimeswidget.LocationDialog.java

protected void initViews(Context context) {
    WidgetSettings.initDisplayStrings(context);

    TextView groupTitle = (TextView) findViewById(R.id.appwidget_location_grouptitle);
    groupTitle.setVisibility(View.GONE);

    ArrayAdapter<WidgetSettings.LocationMode> spinner_locationModeAdapter;
    spinner_locationModeAdapter = new ArrayAdapter<WidgetSettings.LocationMode>(myParent,
            R.layout.layout_listitem_oneline, WidgetSettings.LocationMode.values());
    spinner_locationModeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner_locationMode = (Spinner) findViewById(R.id.appwidget_location_mode);
    spinner_locationMode.setAdapter(spinner_locationModeAdapter);
    spinner_locationMode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final WidgetSettings.LocationMode[] locationModes = WidgetSettings.LocationMode.values();
            WidgetSettings.LocationMode locationMode = locationModes[parent.getSelectedItemPosition()];

            LocationDialogMode dialogMode = (locationMode == WidgetSettings.LocationMode.CUSTOM_LOCATION)
                    ? LocationDialogMode.MODE_CUSTOM
                    : LocationDialogMode.MODE_AUTO;
            setMode(dialogMode);//from   ww w. ja  v a  2  s  .  co m
        }

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

    labl_locationName = (TextView) findViewById(R.id.appwidget_location_name_label);
    text_locationName = (EditText) findViewById(R.id.appwidget_location_name);

    labl_locationLat = (TextView) findViewById(R.id.appwidget_location_lat_label);
    text_locationLat = (EditText) findViewById(R.id.appwidget_location_lat);

    labl_locationLon = (TextView) findViewById(R.id.appwidget_location_lon_label);
    text_locationLon = (EditText) findViewById(R.id.appwidget_location_lon);

    progress_getfix = (ProgressBar) findViewById(R.id.appwidget_location_getfixprogress);
    progress_getfix.setVisibility(View.GONE);

    button_getfix = (ImageButton) findViewById(R.id.appwidget_location_getfix);
    button_getfix.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getFixHelper.getFix();
        }
    });

    getFixUI = new GetFixUI1(text_locationName, text_locationLat, text_locationLon, progress_getfix,
            button_getfix);
    getFixHelper = new GetFixHelper(myParent, getFixUI);

    if (!getFixHelper.isLocationEnabled()) {
        button_getfix.setImageResource(GetFixUI.ICON_GPS_DISABLED);
    }
}