Android ToggleButton - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ToggleButton class.

This code example shows how to use the following methods:setLayoutParams, setButtonDrawable, setBackgroundDrawable
     
    // create a new ImageView for each item referenced by the Adapter 
    public View getView(int position, View convertView, ViewGroup parent) {
        ToggleButton imageButton;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	imageButton = new ToggleButton(mContext);
        	imageButton.setLayoutParams(new GridView.LayoutParams(110, 110));
        	/**imageButton.setScaleType(ToggleButton.ScaleType.CENTER_CROP); 
        	imageButton.setPadding(8, 8, 8, 8);*/ 
        } else { 
        	imageButton = (ToggleButton) convertView;
        } 
         
        imageButton.setBackgroundDrawable(null);
        imageButton.setButtonDrawable(mThumbIds[position]);
        return imageButton;
    } 
 
    // references to our images 
    private Integer[] mThumbIds = {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTag
            button.setTextOn(label);
            button.setPadding(0, 1, 0, 0);
 
            button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    setImportance((Integer)button.getTag());
                } 
            }); 
            button.setTag(i);
 
            buttons.add(button);
            container.addView(button);
        } 
 
        if (usedWidth > width * 2 /3 ) {
            getView().findViewById(R.id.display_row_title).setVisibility(View.GONE);
        } 
    } 
 
    @Override 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCheckedChangeListener, setText, setWidth, setTextOff, setTextOn
		this.mLayout = new RelativeLayout(mContext);
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.FILL_PARENT);
		params.setMargins(0, 3, 0, 0);
		this.mLayout.setLayoutParams(params);
		this.mButton = new ToggleButton(mContext);
		this.mButton.setText("Torch");
		this.mButton.setTextOn("Torch");
		this.mButton.setTextOff("Torch");
		this.mButton.setWidth(LayoutParams.FILL_PARENT);
		this.mButton
				.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
 
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						if (isChecked) {
							ledOn(); 
						} else { 
							ledOff(); 
						} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setVisibility, setChecked
		PassageChangeMediator.getInstance().forcePageUpdate(); 
	} 
 
	public void update() { 
        boolean showStrongsToggle = canShow();
        mButton.setVisibility(showStrongsToggle? View.VISIBLE : View.GONE);
        if (showStrongsToggle) {
	        boolean isShowstrongs = CommonUtils.getSharedPreferences().getBoolean("show_strongs_pref", true);
	        mButton.setChecked(isShowstrongs);
        } 
	} 
 
	/** return true if Strongs are relevant to this doc & screen */ 
	@Override 
	public boolean canShow() { 
		return isEnoughRoomInToolbar() && ControlFactory.getInstance().getDocumentControl().isStrongsInBook(); 
	} 
 
	@Override 
	public int getPriority() { 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setVisibility, setOnCheckedChangeListener, setChecked
		  boolean enabled = getSharedPreferences().getBoolean(getKey()+"_y", false);
		  //Log.d("Preference", getTitle()+ "   enabled at start: "+enabled + "   y enabled: "+yEnabled); 
//		  if (yaxis != null) 
//			  enabled = yaxis.isChecked(); 
		  if (yEnabled)  {
			  yaxis.setChecked(enabled);
			  setBarState(!enabled);
			  yaxis.setOnCheckedChangeListener(this);
			  yaxis.setVisibility(View.VISIBLE);
		  } else { 
			  yaxis.setVisibility(View.INVISIBLE);
		  } 
 
		bar.setMax(maximum + minimum);
		bar.setProgress((int) this.oldValue);
		bar.setOnSeekBarChangeListener(this);
//		 
//		 
		setMonitorBox(bar.getProgress());
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isChecked
		button.setOnClickListener(new OnClickListener() {
			@Override 
			public void onClick(final View v) {
				TransitionDrawable drawable = (TransitionDrawable) image
						.getDrawable();
				if (button.isChecked()) {
					drawable.startTransition(1000);
				} else { 
					drawable.reverseTransition(1000);
				} 
			} 
		}); 
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setText, setChecked, setTextOff, setTextOn
		view = (ToggleButton) mInflater.inflate(AmlBuilder.localResources.getInt("aml_input_togglebutton"), null);
		Node label = n.getChildNodes().item(0);
		Node offTextNode = n.getAttributes().getNamedItem("offtext");
		Node onTextNode = n.getAttributes().getNamedItem("ontext");
		Node checkedNode = n.getAttributes().getNamedItem("checked");
		if (offTextNode != null) view.setTextOff(offTextNode.getNodeValue());
		if (onTextNode != null) view.setTextOn(onTextNode.getNodeValue());
		String checked = "";
		if (checkedNode != null) checked = checkedNode.getNodeValue().toLowerCase();
		if (label != null && label.getNodeValue().trim().length() > 0) view.setText(label.getNodeValue());
		else if (offTextNode != null && !checked.equals("yes")) view.setText(offTextNode.getNodeValue());
		else if (onTextNode != null && checked.equals("yes")) view.setText(onTextNode.getNodeValue());
		view.setChecked(checked.equals("yes"));
 		AmlBuilder.applyActionAttribute(view, "tap", n.getAttributes().getNamedItem("tap"));
		Log.d(TAG, "New ToggleButton input construction complete from XML node " + n.toString());
	} 
 
	/** 
	 * Get the View created from this object 
	 * @return View to be inserted into parent layout 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setChecked, setTextOff, setTextOn
  public static void promptForBoolean(Context context, String caption,
      String label, final PromptResultHandler<Boolean> resultHandler) {
    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setTitle(caption);
    alert.setMessage(label);
    final ToggleButton input = new ToggleButton(context);
    input.setTextOn("On/open");
    input.setTextOff("Off/closed");
    input.setChecked(false);
    alert.setView(input);
 
    alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
      @Override 
      public void onClick(DialogInterface dialog, int which) {
        boolean value = input.isChecked();
        resultHandler.closed(true, value);
      } 
    }); 
 
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCheckedChangeListener
		ssb.append(String.valueOf(mRelayNumber));
		ssb.setSpan(new SubscriptSpan(), 5, 6, 0);
		ssb.setSpan(new RelativeSizeSpan(0.7f), 5, 6, 0);
		mLabel.setText(ssb);
		mButton = (ToggleButton) targetView.getChildAt(1);
		mButton.setOnCheckedChangeListener(this);
	} 
 
	public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
		if (isChecked) {
			mButton.setBackgroundDrawable(mOnBackground);
		} else { 
			mButton.setBackgroundDrawable(mOffBackground);
		} 
		if (mActivity != null) {
			mActivity.sendCommand(DemoKitActivity.RELAY_COMMAND,
					mCommandTarget, isChecked ? 1 : 0);
		} 
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCheckedChangeListener, setText, setTextOff, setTextOn
		this.name = name;
		this.messageToggleOn = "/" + name + "/1";
		this.messageToggleOff = "/" + name + "/0";
		 
		 
		button.setOnCheckedChangeListener(this);
		button.setText(name);
		button.setTextOn(name);
		button.setTextOff(name);
	} 
	 
	private ToggleOSCWrapper(String name, String msgToggleOn, String msgToggleOff, ToggleButton button, QuickOSCActivity parentActivity) {
		this.parentActivity = parentActivity;
		this.name = name;
		this.messageToggleOn = (msgToggleOn == null || msgToggleOn.equals("")) ? "/" + name + "/1" : msgToggleOn;
		this.messageToggleOff = (msgToggleOff == null || msgToggleOff.equals("")) ? "/" + name + "/0" : msgToggleOff;
		 
		 
		button.setOnCheckedChangeListener(this);
		button.setText(name);
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android ToggleButton Questions & Answers:

Other Android ToggleButton Examples

1:	ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton);
2:	toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
3:	    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-
1:	ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton);
2:	toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
3:	    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

Read More

1:	public void onToggleClicked(View view) {
2:	    // Is the toggle on?
3:	    boolean on = ((ToggleButton) view).isChecked();
4:	    
5:	    if (on) {

Read More

See Code Examples for Android ToggleButton Methods: