當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。