本文整理了Java中android.widget.Switch.setOnCheckedChangeListener()
方法的一些代码示例,展示了Switch.setOnCheckedChangeListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Switch.setOnCheckedChangeListener()
方法的具体详情如下:
包路径:android.widget.Switch
类名称:Switch
方法名:setOnCheckedChangeListener
暂无
代码示例来源:origin: stackoverflow.com
Switch s = (Switch) findViewById(R.id.SwitchID);
if (s != null) {
s.setOnCheckedChangeListener(this);
}
/* ... */
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(this, "The Switch is " + (isChecked ? "on" : "off"),
Toast.LENGTH_SHORT).show();
if(isChecked) {
//do stuff when Switch is ON
} else {
//do stuff when Switch if OFF
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressWarnings("ResourceType")
@Override
public void onReady(Bundle savedInstanceState) {
setContentView(R.layout.main);
type=(Spinner)findViewById(R.id.type);
ArrayAdapter<String> types=
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.types));
types.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
type.setAdapter(types);
period=(Spinner)findViewById(R.id.period);
ArrayAdapter<String> periods=
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.periods));
periods.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
period.setAdapter(periods);
download=(Switch)findViewById(R.id.download);
((Switch)findViewById(R.id.scheduled))
.setOnCheckedChangeListener(this);
alarms=(AlarmManager)getSystemService(ALARM_SERVICE);
}
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressWarnings("ResourceType")
@Override
public void onReady(Bundle savedInstanceState) {
setContentView(R.layout.main);
type=findViewById(R.id.type);
ArrayAdapter<String> types=
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.types));
types.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
type.setAdapter(types);
period=findViewById(R.id.period);
ArrayAdapter<String> periods=
new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.periods));
periods.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
period.setAdapter(periods);
download=findViewById(R.id.download);
scheduled=findViewById(R.id.scheduled);
scheduled.setOnCheckedChangeListener(this);
alarms=(AlarmManager)getSystemService(ALARM_SERVICE);
jobs=(JobScheduler)getSystemService(JOB_SCHEDULER_SERVICE);
}
代码示例来源:origin: facebook/facebook-android-sdk
mEmailPermSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
mUserPostsPermSwitch.setOnCheckedChangeListener(new CompoundButton
.OnCheckedChangeListener() {
@Override
mPublishPostPermSwitch.setOnCheckedChangeListener(new CompoundButton
.OnCheckedChangeListener() {
@Override
mAppPermSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
代码示例来源:origin: xfumihiro/ViewInspector
public SettingsMenu(final Context context) {
super(context);
ViewInspector.runtimeComponentMap.get(context).inject(this);
inflate(context, R.layout.view_inspector_settings_menu, this);
Switch logViewEventsSwitch = (Switch) findViewById(R.id.log_view_events_switch);
logViewEventsSwitch.setChecked(logViewEvents.get());
logViewEventsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
logViewEvents.set(isChecked);
}
});
View viewFilter = findViewById(R.id.view_filter);
viewFilter.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
new SetViewFilterDialog(
new ContextThemeWrapper(context, BaseDialog.getDialogTheme(context))).show();
}
});
}
}
代码示例来源:origin: xfumihiro/ViewInspector
outlineSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
showOutline.set(isChecked);
marginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
showMargin.set(isChecked);
paddingSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
showPadding.set(isChecked);
代码示例来源:origin: xfumihiro/ViewInspector
scalpel3dSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
scalpel3d.set(isChecked);
scalpelWireframeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
scalpelWireframe.set(isChecked);
scalpelIdSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
scalpelId.set(isChecked);
代码示例来源:origin: xfumihiro/ViewInspector
mProbeMeasureSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
probeMeasures.set(isChecked);
showMeasureCountSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
showMeasureCount.set(isChecked);
代码示例来源:origin: lygttpod/SuperTextView
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
代码示例来源:origin: stackoverflow.com
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem menuItem = menu.findItem(R.id.myswitch);
View view = MenuItemCompat.getActionView(menuItem);
Switch switcha = (Switch) view.findViewById(R.id.switchForActionBar);
switcha.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// do anything here on check changed
}
});
return super.onCreateOptionsMenu(menu);
}
代码示例来源:origin: curtis2/SuperVideoPlayer
@Override
protected void initOtherView() {
mtanMuSwitch= (Switch) mRoot.findViewById(R.id.switch_tanmu);
mtanMuSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
mtanMuSwitch.setBackgroundColor(getResources().getColor(R.color.video_red_color));
//开启弹幕
mDanmakuView.prepare(mParser, mDanmakuContext);
mDanmakuView.show();
}else{
mtanMuSwitch.setBackgroundColor(getResources().getColor(R.color.video_gray_color));
//关闭弹幕
mDanmakuView.hide();
}
}
});
}
public void setTanMuView(IDanmakuView tanMuView,DanmakuContext mDanmakuContext,BaseDanmakuParser mParser ) {
代码示例来源:origin: willowtreeapps/Hyperion-Android
public BooleanPreferenceViewHolder(View itemView, SharedPreferences sharedPreferences) {
super(itemView);
switchValue = itemView.findViewById(R.id.hsp_navigation_preference_value);
switchValue.setOnCheckedChangeListener(new CheckChangedListener(sharedPreferences));
}
代码示例来源:origin: palaima/DebugDrawer
@Override
public View getView(@NonNull final LayoutInflater inflater, @NonNull final LinearLayout parent) {
final Context context = parent.getContext();
if (contextRef == null) {
contextRef = new WeakReference<>(context);
}
View viewGroup = inflater.inflate(R.layout.dd_debug_drawer_module_actions_switch, parent, false);
final TextView textView = viewGroup.findViewById(R.id.action_switch_name);
textView.setText(name);
switchButton = viewGroup.findViewById(R.id.action_switch_switch);
switchButton.setOnCheckedChangeListener(switchListener);
return viewGroup;
}
代码示例来源:origin: palaima/DebugDrawer
@Override
@NonNull
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
final View view = inflater.inflate(R.layout.dd_debug_drawer_item_fps, parent, false);
final Switch showSwitch = (Switch) view.findViewById(R.id.dd_debug_fps);
showSwitch.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
FpsModule.this.isChecked = isChecked;
if (isChecked) {
program.play();
} else {
program.stop();
}
}
});
return view;
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate your Menu
getMenuInflater().inflate(R.menu.your_menu, menu);
// Get the action view used in your toggleservice item
final MenuItem toggleservice = menu.findItem(R.id.toggleservice);
final Switch actionView = (Switch) toggleservice.getActionView();
actionView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Start or stop your Service
}
});
return super.onCreateOptionsMenu(menu);
}
代码示例来源:origin: palaima/DebugDrawer
@Override
public void onStart() {
final boolean isChecked = readValue();
switchButton.setOnCheckedChangeListener(null);
switchButton.setChecked(isChecked);
switchButton.setOnCheckedChangeListener(switchListener);
if (shouldEmitFirstValue && listener != null) {
listener.onCheckedChanged(isChecked);
}
}
代码示例来源:origin: palaima/DebugDrawer
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
final View view = inflater.inflate(R.layout.dd_debug_drawer_item_picasso, parent, false);
indicatorView = view.findViewById(R.id.dd_debug_picasso_indicators);
cacheLabel = view.findViewById(R.id.dd_debug_picasso_cache_size);
cacheHitsLabel = view.findViewById(R.id.dd_debug_picasso_cache_hit);
cacheMissesLabel = view.findViewById(R.id.dd_debug_picasso_cache_miss);
decodedLabel = view.findViewById(R.id.dd_debug_picasso_decoded);
decodedTotalLabel = view.findViewById(R.id.dd_debug_picasso_decoded_total);
decodedAverageLabel = view.findViewById(R.id.dd_debug_picasso_decoded_avg);
transformedLabel = view.findViewById(R.id.dd_debug_picasso_transformed);
transformedTotalLabel = view.findViewById(R.id.dd_debug_picasso_transformed_total);
transformedAverageLabel = view.findViewById(R.id.dd_debug_picasso_transformed_avg);
picasso.setIndicatorsEnabled(picasso.areIndicatorsEnabled());
indicatorView.setChecked(picasso.areIndicatorsEnabled());
indicatorView.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
picasso.setIndicatorsEnabled(isChecked);
}
});
refresh();
return view;
}
代码示例来源:origin: doggycoder/AndroidOpenGLDemo
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_light);
glView= (GLSurfaceView) findViewById(R.id.glView);
glView.setEGLContextClientVersion(2);
glView.setRenderer(this);
glView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
buffer=ByteBuffer.allocateDirect(data.length*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
buffer.position(0);
buffer.put(data);
int[] switchId=new int[]{
R.id.ambient,R.id.diffuse,R.id.specular
};
for (int id:switchId){
((Switch)findViewById(id)).setOnCheckedChangeListener(this);
}
}
代码示例来源:origin: eclipse/paho.mqtt.android
@Override
public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater){
inflater.inflate(R.menu.menu_connection, menu);
connectSwitch = (Switch) menu.findItem(R.id.connect_switch).getActionView().findViewById(R.id.switchForActionBar);
connectSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
((MainActivity) getActivity()).connect(connection);
changeConnectedState(true);
} else {
((MainActivity) getActivity()).disconnect(connection);
changeConnectedState(false);
}
}
});
changeConnectedState(connection.isConnected());
super.onCreateOptionsMenu(menu, inflater);
}
代码示例来源:origin: julian-klode/dns66
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_dns, container, false);
RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.dns_entries);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new ItemRecyclerViewAdapter(MainActivity.config.dnsServers.items, 2);
mRecyclerView.setAdapter(mAdapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(mAdapter));
itemTouchHelper.attachToRecyclerView(mRecyclerView);
Switch dnsEnabled = (Switch) rootView.findViewById(R.id.dns_enabled);
dnsEnabled.setChecked(MainActivity.config.dnsServers.enabled);
dnsEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
MainActivity.config.dnsServers.enabled = isChecked;
FileHelper.writeSettings(getContext(), MainActivity.config);
}
});
ExtraBar.setup(rootView.findViewById(R.id.extra_bar), "dns");
return rootView;
}
内容来源于网络,如有侵权,请联系作者删除!