当前位置: 首页>>代码示例>>Java>>正文


Java Switch.setChecked方法代码示例

本文整理汇总了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());
}
 
开发者ID:RobinCaroff,项目名称:MyGeofencer,代码行数:24,代码来源:EditGeofenceActivity.java

示例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());
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:24,代码来源:BlockingItemViewHolder.java

示例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));
}
 
开发者ID:WindFromFarEast,项目名称:SmartButler,代码行数:23,代码来源:SettingActivity.java

示例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);
		}
	});
	
}
 
开发者ID:Specher,项目名称:AllHuaji,代码行数:19,代码来源:MainActivity.java

示例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);

}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:13,代码来源:PreferencesActivity.java

示例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();
        }
    });
}
 
开发者ID:vpaliyX,项目名称:Material-Motion,代码行数:16,代码来源:MainActivity.java

示例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);

}
 
开发者ID:interritus1996,项目名称:memento-app,代码行数:39,代码来源:LogActivity.java

示例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;
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:59,代码来源:SourceSettingsAdapter.java

示例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;
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:31,代码来源:NotificationAdapter.java

示例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);
    }
}
 
开发者ID:DysaniazzZ,项目名称:TopActivity,代码行数:16,代码来源:SettingsActivity.java

示例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);
                }
            }
        });
    }
}
 
开发者ID:MBach,项目名称:home-automation,代码行数:37,代码来源:DeviceActivity.java

示例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);

}
 
开发者ID:Hultron,项目名称:LifeHelper,代码行数:39,代码来源:SettingActivity.java

示例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();
}
 
开发者ID:Snooze986,项目名称:SonoESEO-Android,代码行数:34,代码来源:ActivitiesFragment.java

示例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);

}
 
开发者ID:CityZenApp,项目名称:Android-Development,代码行数:43,代码来源:CreatePoiFragment.java

示例15: checkBL

import android.widget.Switch; //导入方法依赖的package包/类
private void checkBL(@SuppressWarnings("SameParameterValue") boolean tralse) {
    for (Switch toggle : switches) {
        toggle.setChecked(tralse);
    }
}
 
开发者ID:zacharee,项目名称:SystemUITuner2,代码行数:6,代码来源:StatBar.java


注:本文中的android.widget.Switch.setChecked方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。