本文整理匯總了Java中android.support.v7.widget.AppCompatSpinner.setSelection方法的典型用法代碼示例。如果您正苦於以下問題:Java AppCompatSpinner.setSelection方法的具體用法?Java AppCompatSpinner.setSelection怎麽用?Java AppCompatSpinner.setSelection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.AppCompatSpinner
的用法示例。
在下文中一共展示了AppCompatSpinner.setSelection方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.support.v7.widget.AppCompatSpinner; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSpinnerDelay = (AppCompatSpinner) findViewById(R.id.spinner_delay);
mSpinnerSlide = (AppCompatSpinner) findViewById(R.id.spinner_slide);
mSpinnerDelay.setAdapter(new ArrayAdapter<>(this, R.layout.spinner, mDelayGravities));
mSpinnerSlide.setAdapter(new ArrayAdapter<>(this, R.layout.spinner, mSlideGravities));
mSpinnerDelay.setSelection(1);
mSpinnerSlide.setSelection(1);
mSpinnerDelay.setOnItemSelectedListener(this);
mSpinnerSlide.setOnItemSelectedListener(this);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(new Adapter());
startMaterialIn();
}
示例2: setupLanguageSelect
import android.support.v7.widget.AppCompatSpinner; //導入方法依賴的package包/類
void setupLanguageSelect(final Context context, final View view) {
AppCompatSpinner spinner = (AppCompatSpinner) view.findViewById(R.id.languageSpinner);
List<String> selections = new ArrayList<>();
selections.add(getResources().getString(R.string.Finnish));
selections.add(getResources().getString(R.string.Swedish));
selections.add(getResources().getString(R.string.English));
ArrayAdapter<String> adapter = new ArrayAdapter<>(this.getActivity(), R.layout.setting_spinner_item, selections);
adapter.setDropDownViewResource(R.layout.setting_spinner_dropdown_item);
spinner.setAdapter(adapter);
String languageSetting = AppPreferences.getLanguageCodeSetting(context);
switch (languageSetting) {
case AppPreferences.LANGUAGE_CODE_FI:
spinner.setSelection(0);
break;
case AppPreferences.LANGUAGE_CODE_SV:
spinner.setSelection(1);
break;
default: // "en"
spinner.setSelection(2);
break;
}
spinner.setOnItemSelectedListener(new LanguageSelectedListener(context));
}
示例3: setupView
import android.support.v7.widget.AppCompatSpinner; //導入方法依賴的package包/類
@Override
public void setupView(View view) {
AppCompatSpinner spinner = (AppCompatSpinner)view.findViewById(R.id.settings_spinner);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(onItemSelectedListener);
if (selectedPos != -1)
spinner.setSelection(selectedPos);
}
示例4: onCreateDialog
import android.support.v7.widget.AppCompatSpinner; //導入方法依賴的package包/類
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
final LayoutInflater dialogInflater = getActivity().getLayoutInflater();
final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false);
name = (AppCompatEditText) view.findViewById(R.id.name);
host = (AppCompatEditText) view.findViewById(R.id.host);
port = (AppCompatEditText) view.findViewById(R.id.port);
path = (AppCompatEditText) view.findViewById(R.id.path);
hostContainer = view.findViewById(R.id.hostContainer);
pathContainer = view.findViewById(R.id.pathContainer);
username = (AppCompatEditText) view.findViewById(R.id.username);
usernameContainer = view.findViewById(R.id.usernameContainer);
password = (AppCompatEditText) view.findViewById(R.id.password);
passwordContainer = view.findViewById(R.id.passwordContainer);
scheme = (AppCompatSpinner) view.findViewById(R.id.scheme);
anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous);
anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE);
passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE);
}
});
if(connection_id != 0){
NetworkConnection connection =
NetworkConnection.fromConnectionId(getActivity(), connection_id);
ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter();
int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase());
scheme.setSelection(spinnerPosition);
name.setText(connection.getName());
host.setText(connection.getHost());
port.setText(Integer.toString(connection.getPort()));
path.setText(connection.getPath());
username.setText(connection.getUserName());
password.setText(connection.getPassword());
anonymous.setChecked(connection.isAnonymousLogin());
if(SERVER.equals(connection.getType())){
hostContainer.setVisibility(View.GONE);
pathContainer.setVisibility(View.VISIBLE);
}
}
builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection");
builder.setView(view);
builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final BaseActivity activity = (BaseActivity) getActivity();
NetworkConnection networkConnection = getNetworkConnection();
if(validate(networkConnection)){
new CreateConnectionTask(activity, networkConnection).executeOnExecutor(
ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY));
}
}
});
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
示例5: setSelectedItemPosition
import android.support.v7.widget.AppCompatSpinner; //導入方法依賴的package包/類
@BindingAdapter("selectedItemPosition")
public void setSelectedItemPosition(AppCompatSpinner spinner,int position)
{
if(spinner.getSelectedItemPosition()!=position)
spinner.setSelection(position);
}