Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd just <em>re-use</em> the <code>RadioGroup</code> like so: (please note the <code>onClick</code> attribute,i.e. a button click will trigger your Activity's <code>onToggle(View)</code> method.</p> <pre><code>&lt;RadioGroup android:id="@+id/toggleGroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:orientation="horizontal" &gt; &lt;ToggleButton android:id="@+id/btn_Letter" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:textSize="14sp" android:textOn="Letter" android:textOff="Letter" android:onClick="onToggle" android:checked="true" /&gt; &lt;ToggleButton android:id="@+id/btn_A4" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:textSize="14sp" android:textOn="A4" android:textOff="A4" android:onClick="onToggle" /&gt; &lt;/RadioGroup&gt; </code></pre> <p>In your Activity, or some place else, you can define a listener, e.g.</p> <pre><code>static final RadioGroup.OnCheckedChangeListener ToggleListener = new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(final RadioGroup radioGroup, final int i) { for (int j = 0; j &lt; radioGroup.getChildCount(); j++) { final ToggleButton view = (ToggleButton) radioGroup.getChildAt(j); view.setChecked(view.getId() == i); } } }; </code></pre> <p>and register it, for instance in <code>onCreate()</code>:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.scan_settings); ((RadioGroup) findViewById(R.id.toggleGroup)).setOnCheckedChangeListener(ToggleListener); } </code></pre> <p>finally in <code>onToggle(View)</code>, you would do whatever needs to happen, specific to your app. and also call the RadioGroup's <strong>check</strong> method, with the toggled view's id. Like so:</p> <pre><code>public void onToggle(View view) { ((RadioGroup)view.getParent()).check(view.getId()); // app specific stuff .. } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload