本文整理汇总了Java中android.widget.Switch.setChecked方法的典型用法代码示例。如果您正苦于以下问题:Java Switch.setChecked方法的具体用法?Java Switch.setChecked怎么用?Java Switch.setChecked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.Switch
的用法示例。
在下文中一共展示了Switch.setChecked方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
myGeofence = intent.getParcelableExtra(MYGEOFENCE_EXTRA);
if(myGeofence == null) {
Log.e(EditGeofenceActivity.class.getSimpleName(), "Intent extra does not contain a MyGeofence object");
finish();
}
((MyGeofencerApplication) getApplication()).getMyGeofencerComponent().inject(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
setContentView(R.layout.activity_edit_geofence);
nameEditText = (EditText) findViewById(R.id.name);
nameEditText.setText(myGeofence.getName());
monitorSwitch = (Switch) findViewById(R.id.monitor_switch);
monitorSwitch.setChecked(myGeofence.isEnabled());
}
示例2: BlockingItemViewHolder
import android.widget.Switch; //导入方法依赖的package包/类
BlockingItemViewHolder(View itemView, final BrowserFragment fragment) {
super(itemView);
this.fragment = fragment;
final Switch switchView = itemView.findViewById(R.id.blocking_switch);
switchView.setChecked(fragment.getSession().isBlockingEnabled());
switchView.setOnCheckedChangeListener(this);
final View helpView = itemView.findViewById(R.id.help_trackers);
helpView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (browserFragment != null) {
browserFragment.onClick(view);
}
}
});
trackerCounter = itemView.findViewById(R.id.trackers_count);
updateTrackers(fragment.getSession().getBlockedTrackers().getValue());
}
示例3: initView
import android.widget.Switch; //导入方法依赖的package包/类
private void initView()
{
switch_voice= (Switch) findViewById(R.id.switch_voice);
switch_sms= (Switch) findViewById(R.id.switch_sms);
ll_check_version= (LinearLayout) findViewById(R.id.ll_check_version);
tv_version_name= (TextView) findViewById(R.id.tv_version_name);
ll_scan_qrcode= (LinearLayout) findViewById(R.id.ll_scan_qrcode);
ll_my_qrcode= (LinearLayout) findViewById(R.id.ll_my_qrcode);
ll_location= (LinearLayout) findViewById(R.id.ll_location);
//获取当前版本信息显示在界面上
showCurrentVersionInfo();
//为各种开关设置监听事件
switch_voice.setOnClickListener(this);
switch_sms.setOnClickListener(this);
ll_check_version.setOnClickListener(this);
ll_scan_qrcode.setOnClickListener(this);
ll_my_qrcode.setOnClickListener(this);
ll_location.setOnClickListener(this);
//进入界面后读取之前保存的开关状态
switch_voice.setChecked(SharedUtils.getBoolean("voice_key",false));
switch_sms.setChecked(SharedUtils.getBoolean("sms_key",false));
}
示例4: onCreate
import android.widget.Switch; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
setting = new Settings(this);
s = (Switch) findViewById(R.id.switch1);
s.setChecked(setting.isStarted());
s.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO 自动生成的方法存根
setting.setStarted(isChecked);
}
});
}
示例5: setBoxes
import android.widget.Switch; //导入方法依赖的package包/类
private void setBoxes() {
Switch box1= (Switch) findViewById(R.id.prefs_autodel_box);
Switch box2= (Switch) findViewById(R.id.prefs_askenc_box);
Switch box3= (Switch) findViewById(R.id.prefs_savepass_box);
box1.setChecked(SharedData.ASK_DEL_AFTER_ENCRYPTION);
box2.setChecked(SharedData.ASK_ENCRYPTION_CONFIG);
box3.setChecked(SharedData.ASK_KEY_PASSS_CONFIG);
box1.setOnClickListener(this);
box2.setOnClickListener(this);
box3.setOnClickListener(this);
}
示例6: setupWarning
import android.widget.Switch; //导入方法依赖的package包/类
private void setupWarning(){
preferences= PreferenceManager.getDefaultSharedPreferences(this);
preferences.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(preferences,WARNING_KEY);
final MenuItem item=navigation.getMenu().findItem(R.id.enable_message);
Switch view=(Switch)MenuItemCompat.getActionView(item);
view.setChecked(preferences.getBoolean(WARNING_KEY,false));
view.setOnCheckedChangeListener((button,isChecked)->{
if(enabledWarning!=isChecked) {
preferences.edit()
.putBoolean(WARNING_KEY, isChecked)
.apply();
}
});
}
示例7: onCreate
import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log);
final LogAdapter logAdapter = new LogAdapter();
ListView listView = (ListView) findViewById(R.id.log);
listView.setAdapter(logAdapter);
Switch start_switch = (Switch) findViewById(R.id.start_switch);
start_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
MainService.APP_START = 1;
} else {
MainService.APP_START = 0;
}
}
});
if (MainService.APP_START==1) {
start_switch.setChecked(true);
} else {
start_switch.setChecked(false);
}
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
logAdapter.notifyDataSetChanged();
handler.postDelayed(this, 1000);
}
}, 1000);
}
示例8: getView
import android.widget.Switch; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final SourceSetting sourceSetting = sources.get(position);
View v = convertView;
int type = getItemViewType(position);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch (type) {
case PARENT:
v = inflater.inflate(R.layout.list_item_setting_source_parent, parent, false);
break;
case CHILD:
v = inflater.inflate(R.layout.list_item_setting_source_child, parent, false);
break;
default:
break;
}
final TextView sourceNameTextView = (TextView) v.findViewById(R.id.sourceTextView);
final Switch sourceSwitch = (Switch) v.findViewById(R.id.sourceSwitch);
sourceNameTextView.setText(sourceSetting.getCleanName());
SourceSetting src = SourceController.getInstance().getSource(context, sourceSetting.getName());
sourceSwitch.setChecked(src != null && src.isEnabled());
if (!sourceSwitch.isChecked()) {
sourceNameTextView.setTextColor(Color.GRAY);
} else {
sourceNameTextView.setTextColor(Color.BLACK);
}
sourceSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
SourceController.getInstance().toggleSource(getContext(), sourceSetting.getName());
boolean refresh = false;
if (sourceSetting.isParent()) {
SourceController.getInstance().toggleSourceChildren(getContext(),
sourceSetting.getName(),
sourceSwitch.isChecked());
refresh = true;
}
if (sourceSwitch.isChecked()) {
sourceNameTextView.setTextColor(Color.BLACK);
} else {
sourceNameTextView.setTextColor(Color.GRAY);
}
sort();
if (refresh) {
parentActivity.refreshActivity();
}
}
});
return v;
}
示例9: getView
import android.widget.Switch; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_item_notification, null, true);
final NotificationSetting notification = notifications.get(position);
final Switch notificationSwitch = (Switch) rowView.findViewById(R.id.notificationSwitch);
final TextView notificationTextView = (TextView) rowView.findViewById(R.id.notificationTextView);
notificationSwitch.setChecked(notification.isEnabled());
notificationTextView.setText(notification.getTime());
if (!notification.isEnabled()) {
notificationTextView.setTextColor(Color.GRAY);
}
notificationSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notification.setEnabled(notificationSwitch.isChecked());
if (notificationSwitch.isChecked()) {
notificationTextView.setTextColor(Color.BLACK);
} else {
notificationTextView.setTextColor(Color.GRAY);
}
parentActivity.updateChanges(notifications);
}
});
return rowView;
}
示例10: onCreate
import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
mContext = this;
mSwShowDetails = (Switch) findViewById(R.id.sw_show_details);
mSwShowDetails.setOnCheckedChangeListener(this);
mTrackerServiceIntent = new Intent(mContext, TrackerService.class);
if (getIntent().getBooleanExtra(EXTRA_FROM_QS_TILE, false)) {
mSwShowDetails.setChecked(true);
}
}
示例11: populate
import android.widget.Switch; //导入方法依赖的package包/类
private void populate(final boolean enabled, List<DeviceActionDAO> defaultActions, List<StoryDeviceActionDAO> existingActions) {
LinearLayout layout;
if (enabled) {
layout = findViewById(R.id.storyEnabledLinearLayout);
} else {
layout = findViewById(R.id.storyDisabledLinearLayout);
}
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 8, 0, 8);
for (final DeviceActionDAO action : defaultActions) {
Switch s = new Switch(this);
s.setText(action.getName());
s.setLayoutParams(lp);
// Check the matching switch for every list
for (StoryDeviceActionDAO existingAction : existingActions) {
if (enabled && existingAction.isEnabled() && existingAction.getActionId() == action.getId()) {
s.setChecked(true);
break;
} else if (!enabled && !existingAction.isEnabled() && existingAction.getActionId() == action.getId()) {
s.setChecked(true);
break;
}
}
layout.addView(s);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) {
db.createActionForStoryAndDevice(storyId, enabled, action);
} else {
db.deleteActionForStoryAndDevice(storyId, enabled, action);
}
}
});
}
}
示例12: initView
import android.widget.Switch; //导入方法依赖的package包/类
private void initView() {
//是否语音
mSwSpeack = (Switch) findViewById(R.id.sw_speak);
boolean isSpeak = ShareUtil.getBoolean(this, "isSpeak", false);
mSwSpeack.setChecked(isSpeak);
mSwSpeack.setOnClickListener(this);
//是否短信
mSwSms = (Switch) findViewById(R.id.sw_sms);
boolean isSms = ShareUtil.getBoolean(this, "isSms", false);
mSwSms.setChecked(isSms);
mSwSms.setOnClickListener(this);
//检查版本
mUpdate = (LinearLayout) findViewById(R.id.ll_update);
mUpdate.setOnClickListener(this);
mTvVersion = (TextView) findViewById(R.id.tv_version);
try {
getVersionNameAndCode();
mTvVersion.setText(String.format("当前版本:%s", versionName));
} catch (PackageManager.NameNotFoundException e) {
mTvVersion.setText("无法获取当前版本,请检查网络");
}
//扫一扫
mQrcodeScan = (LinearLayout) findViewById(R.id.qrcode_scan);
mQrcodeScan.setOnClickListener(this);
mScanResult = (TextView) findViewById(R.id.tv_scan_result);
//生成二维码
mQrcodeShare = (LinearLayout) findViewById(R.id.qrcode_share);
mQrcodeShare.setOnClickListener(this);
//我的位置
mMyLocation = (LinearLayout) findViewById(R.id.my_location);
mMyLocation.setOnClickListener(this);
}
示例13: onClick
import android.widget.Switch; //导入方法依赖的package包/类
/**
* On click on the sort button.
* It will open a dialog with two switch to sort the list of categories or not and by ascending
* dates or not.
*/
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(ctx);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_sort);
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
final Switch switchCategorized = dialog.findViewById(R.id.switchCategorized);
final Switch switchAscending = dialog.findViewById(R.id.switchAscending);
switchCategorized.setChecked(Content.categorized);
switchAscending.setChecked(Content.ascendingSort);
Button validate = dialog.findViewById(R.id.validate);
validate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Content.categorized = switchCategorized.isChecked();
Content.ascendingSort = switchAscending.isChecked();
sort();
dialog.dismiss();
}
});
dialog.show();
}
示例14: openingHoursLayoutSetup
import android.widget.Switch; //导入方法依赖的package包/类
private void openingHoursLayoutSetup() {
hoursSwitch24_7 = (Switch) getActivity().findViewById(R.id.hoursSwitch24_7);
hoursSwitch24_7.setChecked(false);
extendedOpeningHoursContainer = (LinearLayout) getActivity().findViewById(R.id.extendedOpeningHoursContainer);
extendedOpeningHoursContainer.setVisibility(View.VISIBLE);
openingHours = (TextView) getActivity().findViewById(R.id.openingHours);
closingHours = (TextView) getActivity().findViewById(R.id.closingHours);
//week CheckBoxes
checkboxMonday = (CheckBox) getActivity().findViewById(R.id.checkboxMonday);
checkboxTuesday = (CheckBox) getActivity().findViewById(R.id.checkboxTuesday);
checkboxWednesday = (CheckBox) getActivity().findViewById(R.id.checkboxWednesday);
checkboxThursday = (CheckBox) getActivity().findViewById(R.id.checkboxThursday);
checkboxFriday = (CheckBox) getActivity().findViewById(R.id.checkboxFriday);
checkboxSaturday = (CheckBox) getActivity().findViewById(R.id.checkboxSaturday);
checkboxSunday = (CheckBox) getActivity().findViewById(R.id.checkboxSunday);
checkboxAll = (CheckBox) getActivity().findViewById(R.id.checkboxAll);
checkboxMonday.setOnClickListener(openingHoursViewListener);
checkboxTuesday.setOnClickListener(openingHoursViewListener);
checkboxWednesday.setOnClickListener(openingHoursViewListener);
checkboxThursday.setOnClickListener(openingHoursViewListener);
checkboxFriday.setOnClickListener(openingHoursViewListener);
checkboxSaturday.setOnClickListener(openingHoursViewListener);
checkboxSunday.setOnClickListener(openingHoursViewListener);
checkboxAll.setOnClickListener(openingHoursViewListener);
hoursSwitch24_7.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
//do stuff when Switch is ON
extendedOpeningHoursContainer.setVisibility(View.GONE);
} else {
//do stuff when Switch if OFF
extendedOpeningHoursContainer.setVisibility(View.VISIBLE);
}
}
});
openingHours.setOnClickListener(openingHoursViewListener);
closingHours.setOnClickListener(openingHoursViewListener);
}
示例15: checkBL
import android.widget.Switch; //导入方法依赖的package包/类
private void checkBL(@SuppressWarnings("SameParameterValue") boolean tralse) {
for (Switch toggle : switches) {
toggle.setChecked(tralse);
}
}