本文整理了Java中android.widget.Spinner.setAdapter()
方法的一些代码示例,展示了Spinner.setAdapter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spinner.setAdapter()
方法的具体详情如下:
包路径:android.widget.Spinner
类名称:Spinner
方法名:setAdapter
暂无
代码示例来源:origin: stackoverflow.com
Spinner s = (Spinner)Util.findViewById(view, R.id.sound, R.id.spinner);
s.setAdapter(adapter);
s.setSelection(position, false);
s.setOnItemSelectedListener(listener);
代码示例来源:origin: stackoverflow.com
// you need to have a list of data that you want the spinner to display
List<String> spinnerArray = new ArrayList<String>();
spinnerArray.add("item1");
spinnerArray.add("item2");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, spinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner sItems = (Spinner) findViewById(R.id.spinner1);
sItems.setAdapter(adapter);
代码示例来源:origin: stackoverflow.com
this.setContentView(s, params);
List<Guy> guys = new ArrayList<Guy>();
guys.add(new Guy("Lukas", 18));
guys.add(new Guy("Steve", 20));
MyAdapter adapter = new MyAdapter(guys);
s.setAdapter(adapter);
s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
代码示例来源:origin: stackoverflow.com
Spinner spinner = (Spinner) findViewById(R.id.spinner);
List<String> list = new ArrayList<String>();
list.add("list 1");
list.add("list 2");
list.add("list 3");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(dataAdapter);
代码示例来源:origin: cSploit/android
mPortSpinner.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, ports));
mPortSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id) {
mProtocolSpinner.setAdapter(new ProtocolAdapter());
mProtocolSpinner
.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter,
View view, int position, long id) {
mCharsetSpinner.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, CHARSETS));
mCharsetSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id) {
mUserSpinner.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, USERNAMES));
mUserSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
mMaxSpinner.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, LENGTHS));
mMinSpinner = (Spinner) findViewById(R.id.minSpinner);
mMinSpinner.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, LENGTHS));
代码示例来源:origin: stackoverflow.com
public class HelloSpinner extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array,
// android.R.layout.simple_spinner_item);
R.layout.my_spinner_textview);
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(R.layout.my_spinner_textview);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
//No other modification needed.
代码示例来源:origin: stackoverflow.com
ArrayList<String> years = new ArrayList<String>();
int thisYear = Calendar.getInstance().get(Calendar.YEAR);
for (int i = 1900; i <= thisYear; i++) {
years.add(Integer.toString(i));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, years);
Spinner spinYear = (Spinner)findViewById(R.id.yearspin);
spinYear.setAdapter(adapter);
代码示例来源:origin: aurelhubert/ahbottomnavigation
final List<String> titleStates = new ArrayList<>();
for (AHBottomNavigation.TitleState titleState : AHBottomNavigation.TitleState.values()) {
titleStates.add(titleState.toString());
spinnerTitleState.setAdapter(spinnerAdapter);
spinnerTitleState.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_layout, menu);
MenuItem item = menu.findItem(R.id.spinner);
Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);
spinner.setAdapter(adapter); // set the adapter to provide layout of rows and content
spinner.setOnItemSelectedListener(onItemSelectedListener); // set the listener, to perform actions based on item selection
代码示例来源:origin: stackoverflow.com
Locale[] locale = Locale.getAvailableLocales();
ArrayList<String> countries = new ArrayList<String>();
String country;
for( Locale loc : locale ){
country = loc.getDisplayCountry();
if( country.length() > 0 && !countries.contains(country) ){
countries.add( country );
}
}
Collections.sort(countries, String.CASE_INSENSITIVE_ORDER);
Spinner citizenship = (Spinner)findViewById(R.id.input_citizenship);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, countries);
citizenship.setAdapter(adapter);
代码示例来源:origin: ankidroid/Anki-Android
mAllModelIds = new ArrayList<>();
final ArrayList<String> modelNames = new ArrayList<>();
ArrayList<JSONObject> models = getCol().getModels().all();
Collections.sort(models, new JSONNameComparator());
mNoteTypeSpinner.setAdapter(noteTypeAdapter);
noteTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mAllDeckIds = new ArrayList<>();
final ArrayList<String> deckNames = new ArrayList<>();
mNoteDeckSpinner.setAdapter(noteDeckAdapter);
noteDeckAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mNoteDeckSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
mNoteTypeSpinner.setOnItemSelectedListener(new SetNoteTypeListener());
setTitle(R.string.cardeditor_title_add_note);
mNoteTypeSpinner.setOnItemSelectedListener(new EditNoteTypeListener());
setTitle(R.string.cardeditor_title_edit_card);
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public void onDestroyView() {
if (DEBUG) Log.d(TAG, "onDestroyView() called");
spinnerToolbar.setOnItemSelectedListener(null);
spinnerToolbar.setAdapter(null);
super.onDestroyView();
}
代码示例来源:origin: stackoverflow.com
public class ee extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.ww);
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection(){
ArrayList<String> array = new ArrayList<String>();
array.add("item0");
Spinner spinner1;
ArrayAdapter<String> mAdapter;
spinner1= (Spinner) findViewById(R.id.spinner2);
mAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, array);
spinner1.setAdapter(mAdapter);
}
}
代码示例来源:origin: ankidroid/Anki-Android
mActionBarSpinner.setAdapter(mDropDownAdapter);
mActionBarSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mCards = new ArrayList<>();
mCardsListView = (ListView) findViewById(R.id.card_browser_list);
R.array.browser_column1_headings, android.R.layout.simple_spinner_item);
column1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cardsColumn1Spinner.setAdapter(column1Adapter);
mColumn1Index = AnkiDroidApp.getSharedPrefs(getBaseContext()).getInt("cardBrowserColumn1", 0);
cardsColumn1Spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
R.array.browser_column2_headings, android.R.layout.simple_spinner_item);
column2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cardsColumn2Spinner.setAdapter(column2Adapter);
cardsColumn2Spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
代码示例来源:origin: stackoverflow.com
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
代码示例来源:origin: card-io/card.io-Android-SDK
private void setupLanguageList() {
List<String> languages = new ArrayList<>();
for (SupportedLocale<StringKey> locale : LocalizedStringsList.ALL_LOCALES) {
languages.add(locale.getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, languages);
mLanguageSpinner.setAdapter(adapter);
mLanguageSpinner.setSelection(adapter.getPosition("en"));
}
}
代码示例来源:origin: fossasia/pslab-android
final String[] edges = getResources().getStringArray(R.array.edge_choices);
final List<String> channel_one_list = new ArrayList<>( Arrays.asList(channels));
final List<String> channel_two_list = new ArrayList<>( Arrays.asList(channels));
ArrayAdapter<String> edges_adapter = new ArrayAdapter<>(getContext(), R.layout.modified_spinner_dropdown_list, edges);
channelSelectSpinner1.setAdapter(channel_one_adapter);
channelSelectSpinner2.setAdapter(channel_two_adapter);
edgeSelectSpinner1.setAdapter(edges_adapter);
edgeSelectSpinner2.setAdapter(edges_adapter);
channelSelectSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
channelSelectSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.selection);
Spinner spin=(Spinner)findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter<String> aa=new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
items);
aa.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
代码示例来源:origin: stackoverflow.com
setContentView(R.layout.main);
Spinner spinner = (Spinner)findViewById(R.id.spinner1);
List<City> list = new ArrayList<MainActivity.City>();
for(int i = 0; i < 10; i++)
list.add(new City(String.format("City %d", i + 1), (i + 1) * 1000));
spinner.setAdapter(new CityAdapter(this, list));
代码示例来源:origin: jakob-grabner/Circle-Progress-View
List<String> list = new ArrayList<String>();
list.add("Left Top");
list.add("Left Bottom");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
mSpinner.setAdapter(dataAdapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
内容来源于网络,如有侵权,请联系作者删除!