下面列出了怎么用androidx.appcompat.widget.AppCompatSpinner的API类实例代码及写法,或者点击链接到github查看源代码。
@BindingAdapter("identities")
public static void setIdentities(final AppCompatSpinner spinner, final List<IdentityWithNameAndEmail> identities) {
final List<String> representations;
if (identities == null) {
representations = Collections.emptyList();
} else {
representations = Lists.transform(identities, new Function<IdentityWithNameAndEmail, String>() {
@NullableDecl
@Override
public String apply(IdentityWithNameAndEmail input) {
return EmailAddressUtil.toString(input.getEmailAddress());
}
});
}
final ArrayAdapter<String> adapter = new ArrayAdapter<>(
spinner.getContext(),
android.R.layout.simple_spinner_item,
representations);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
private void init(Context context) {
inflate(context, R.layout.post_filter_view, this);
activeBoard = (AppCompatSpinner) findViewById(R.id.active_board);
activeBoard.setOnItemSelectedListener(onBoardClicked());
nameInput = (AppCompatEditText) findViewById(R.id.filter_name);
filterInput = (AppCompatEditText) findViewById(R.id.filter_text);
highlightCheckBox = (AppCompatCheckBox) findViewById(R.id.highlight_checkbox);
saveButton = (AppCompatButton) findViewById(R.id.save_button);
saveButton.setOnClickListener(this);
findViewById(R.id.edit_button).setOnClickListener(this);
findViewById(R.id.cancel_button).setOnClickListener(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_filter);
filterList = (RecyclerView) findViewById(R.id.filter_list);
boardSpinner = (AppCompatSpinner) findViewById(R.id.board_spinner);
initRecyclerView();
Toolbar toolbar = (Toolbar) findViewById(R.id.mimi_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_nav_arrow_back);
toolbar.setLogo(null);
toolbar.setTitle(R.string.edit_filters);
setToolbar(toolbar);
String boardName = getIntent().getStringExtra(EXTRA_BOARD_NAME);
loadBoards(boardName);
}
public void initView() {
Toolbar toolbar = findViewById(R.id.activity_live_wallpaper_config_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
toolbar.setNavigationOnClickListener(view -> finish());
this.container = findViewById(R.id.activity_live_wallpaper_config_container);
AppCompatSpinner weatherKindSpinner = findViewById(R.id.activity_live_wallpaper_config_weatherKindSpinner);
weatherKindSpinner.setOnItemSelectedListener(new WeatherKindSpinnerSelectedListener());
weatherKindSpinner.setAdapter(
new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, weatherKinds)
);
weatherKindSpinner.setSelection(Arrays.binarySearch(weatherKindValues, weatherKindValueNow));
AppCompatSpinner dayNightTypeSpinner = findViewById(R.id.activity_live_wallpaper_config_dayNightTypeSpinner);
dayNightTypeSpinner.setOnItemSelectedListener(new DayNightTypeSpinnerSelectedListener());
dayNightTypeSpinner.setAdapter(
new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, dayNightTypes)
);
dayNightTypeSpinner.setSelection(Arrays.binarySearch(dayNightTypeValues, dayNightTypeValueNow));
Button doneButton = findViewById(R.id.activity_live_wallpaper_config_doneButton);
doneButton.setOnClickListener(v -> {
LiveWallpaperConfigManager.update(
this, weatherKindValueNow, dayNightTypeValueNow);
finish();
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_holy_graph);
cursus = AppSettings.getAppCursus(app);
campus = AppSettings.getAppCampus(app);
Context context = this;
ActionBar bar = getSupportActionBar();
if (bar != null)
context = bar.getThemedContext();
SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(context,
R.array.spinner_projects_galaxy, android.R.layout.simple_spinner_dropdown_item);
spinner = new AppCompatSpinner(this);
spinner.getBackground().setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_ATOP);
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(this);
Toolbar.LayoutParams lp = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.setMarginStart((int) Tools.dpToPx(context, 8));
spinner.setLayoutParams(lp);
if (savedInstanceState != null)
spinner.setSelection(savedInstanceState.getInt(STATE_POSITION));
toolbar.addView(spinner);
toolbar.setContentInsetStartWithNavigation((int) Tools.dpToPx(context, 8));
listView = findViewById(R.id.listView);
listViewAll = findViewById(R.id.listViewAll);
textViewNoItem = findViewById(R.id.textViewNoItem);
galaxy = findViewById(R.id.galaxy);
galaxy.setOnProjectClickListener(this);
listView.setOnItemClickListener(this);
listViewAll.setOnItemClickListener(this);
super.registerGetDataOnOtherThread(this);
super.registerGetDataOnMainTread(this);
super.setActionBarToggle(ActionBarToggle.HAMBURGER);
super.setSelectedMenu(Navigation.MENU_SELECTED_PROJECTS);
super.onCreateFinished();
}