please help create radiogroup/radiobutton sample

26 views
Skip to first unread message

ryan mcaloney

unread,
Feb 11, 2015, 11:24:45 AM2/11/15
to ioio-...@googlegroups.com
im trying to make an app with at least 2 radio groups  with 3 radio buttons each to turn pins on and off
im an extreme newbie to ioio (went through 3 already) and also to java

im able to compile and use the samples provided but i cant seem to get the radio buttons working with pins, i cant even get the sample to work with more then the led_.

im waiting on my local library for some basic java books but im wondering if someone might be willing to help ive been wasting so much time and money i could even offer some money for help

Thanks Ryan
 

Ytai Ben-Tsvi

unread,
Feb 11, 2015, 12:57:21 PM2/11/15
to ioio-...@googlegroups.com
Would you post your code? Also, why do your IOIOs fail? And in what way? How are you powering them? What are you connecting to them?

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

ryan mcaloney

unread,
Feb 11, 2015, 1:48:32 PM2/11/15
to ioio-...@googlegroups.com
I think its more likely that I destroyed them not really a failure but the first one I bought from jaycon and I ordered a jst connector they had I hooked the jst pigtail to 12v from a cigarette light of a car and it lit up like a sparkler on the 4th of july. not sure if the pigtail red wire was actually + or if it was just too much power jaycon never replied. the 2nd the micro usb connector came off and the 3rd I havent managed to destroy yet.

all that aside im really enjoying the ioio and what im learning from it you made a really awesome device thanks.

so my code is really helloioio hacked up to not work!

my edit of main.xml seems good for what im trying to do but MainActivity.java is where im having trouble connecting the radiobuttons to pins. ive tried many different ways with mainactivity.java but i just dont know enough and my books cant get here fast enough.  I know its ugly and probably all wrong and definately incomplete but heres what ive been basically copying and pasting and trying this morning.

MainActivity.java

package ioio.examples.hello;

import ioio.lib.api.DigitalOutput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.widget.ToggleButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
/**
 * This is the main activity of the HelloIOIO example application.
 * 
 * It displays a toggle button on the screen, which enables control of the
 * on-board LED. This example shows a very simple usage of the IOIO, by using
 * the {@link IOIOActivity} class. For a more advanced use case, see the
 * HelloIOIOPower example.
 */
public class MainActivity extends IOIOActivity {
private ToggleButton button_;
    private RadioGroup passseat;
    private RadioGroup driverseat;
private RadioGroup daytimerunninglights;
private RadioGroup passengermirror;
private RadioGroup drivermirror;
    private RadioButton radioBtn1;
    private RadioButton radioBtn2;
private RadioButton radioBtn3;

/**
* Called when the activity is first created. Here we normally initialize
* our GUI.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button_ = (ToggleButton) findViewById(R.id.button);
   // group1
   addListenerRadioGroup1();
   // group2
   addListenerRadioGroup2();
   // group3
   addListenerRadioGroup3();
   // group4
   addListenerRadioGroup4();
   // group5
   addListenerRadioGroup5();
  
}

/**
* This is the thread on which all the IOIO activity happens. It will be run
* every time the application is resumed and aborted when it is paused. The
* method setup() will be called right after a connection with the IOIO has
* been established (which might happen several times!). Then, loop() will
* be called repetitively until the IOIO gets disconnected.
*/
class Looper extends BaseIOIOLooper {
/** The on-board LED. */
private DigitalOutput led_;

/**
* Called every time a connection with IOIO has been established.
* Typically used to open pins.
* @throws ConnectionLostException
*             When IOIO connection is lost.
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
*/
@Override
protected void setup() throws ConnectionLostException {
led_ = ioio_.openDigitalOutput(0, true);
}

/**
* Called repetitively while the IOIO is connected.
* @throws ConnectionLostException
*             When IOIO connection is lost.
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
*/
@Override
public void loop() throws ConnectionLostException {
led_.write(!button_.isChecked());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
}

/**
* A method to create our IOIO thread.
* @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread()
*/
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
}







main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    

<RadioGroup
    android:id="@+id/RadioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="0dp"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="217dp"
        android:layout_height="wrap_content"
        android:text="Driver Seat"
        android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/RadioGroup1Button0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/RadioGroup1Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Low" />

        <RadioButton
            android:id="@+id/RadioGroup1Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="High" />
    </RadioGroup><RadioGroup
        android:id="@+id/RadioGroup2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/radioGroup1"
        android:orientation="horizontal"
        android:layout_marginRight="15dp" >

        <TextView
            android:id="@+id/TextView2"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Passenger Seat"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/RadioGroup2Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/RadioGroup2Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Low" />

        <RadioButton
            android:id="@+id/RadioGroup2Button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="High" />
    </RadioGroup>
    <RadioGroup
        android:id="@+id/RadioGroup3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/RadioGroup3"
        android:orientation="horizontal"
        android:layout_marginRight="15dp" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Daytime Running Lamps"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/radioGroup3Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/RadioGroup3Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="On" />

   
    </RadioGroup>

    <RadioGroup
        android:id="@+id/RadioGroup4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/TextView4"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Drivers Mirror"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/RadioGroup4Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/RadioGroup4Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="On" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/RadioGroup5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/TextView5"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Passenger Mirror"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/RadioGroup5Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/RadioGroup5Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="On" />
    </RadioGroup>

<ToggleButton android:text="ToggleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button"></ToggleButton>

</LinearLayout>

Ytai Ben-Tsvi

unread,
Feb 11, 2015, 2:32:52 PM2/11/15
to ioio-...@googlegroups.com
  1. The 12V cigarette lighter outlet of cars is often unregulated and can jump to 100V or so during ignition. You really don't want to connect your IOIO directly there... Use a regulator that is designed to be plugged in to a lighter jack.
  2. MicroUSB connector coming off is often a sign of sub-par manufacturing quality. Buy your boards from SparkFun or SeeedStudio if you want to get boards which I can personally vouch for.
  3. I see nowhere in your code any attempt to actually do anything with the radio buttons or pins. If you don't yet know how to use radio buttons, this is unrelated to IOIO and the Android developer site has great tutorials and examples. If it is the IOIO part that is causing you confusion, what you want to do is simply open more digital outputs from your setup() method and then write() to them in your loop() method, just like it is done with the on-board LED. The IOIO Wiki on Github has good explanations about all the IOIO APIs. Check it out if you haven't already.

--

ryan mcaloney

unread,
Feb 11, 2015, 2:55:54 PM2/11/15
to ioio-...@googlegroups.com
I wrote hoping someone might be able to give me an example of 1 or 2 radiogroups turning on a couple pins and from there i could build on it. 
my trouble is being a newb to both java and ioio, ive spent alot of time on github and all across the internet, the ioio isnt whats giving me trouble its my lack of knowledge.


Ytai Ben-Tsvi

unread,
Feb 11, 2015, 4:19:01 PM2/11/15
to ioio-...@googlegroups.com
This is a pretty specific request. While it is possible that someone else has written exactly that, it is not extremely likely. It is probably better for you to just learn how to do it yourself. It is really not that hard and there is some very good documentation and tutorials out there to help you get started.
+

On Wed, Feb 11, 2015 at 11:55 AM, ryan mcaloney <rmca...@gmail.com> wrote:
I wrote hoping someone might be able to give me an example of 1 or 2 radiogroups turning on a couple pins and from there i could build on it. 
my trouble is being a newb to both java and ioio, ive spent alot of time on github and all across the internet, the ioio isnt whats giving me trouble its my lack of knowledge.


ryan mcaloney

unread,
Feb 12, 2015, 9:49:59 AM2/12/15
to ioio-...@googlegroups.com
its amazing how much this one sentence helped me "what you want to do is simply open more digital outputs from your setup() method and then write() to them in your loop() method, just like it is done with the on-board LED" from that tip i came up with what i beleive is working code.
Thanks
Ryan 



MainActvity.java

package ioio.examples.hello;

import ioio.lib.api.DigitalOutput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.widget.RadioButton;

/**
 * This is the main activity of the HelloIOIO example application.
 * 
 * It displays a toggle Button on the screen, which enables control of the
 * on-board LED. This example shows a very simple usage of the IOIO, by using
 * the {@link IOIOActivity} class. For a more advanced use case, see the
 * HelloIOIOPower example.
 */
public class MainActivity extends IOIOActivity {
private RadioButton Button0;
private RadioButton Button1;
private RadioButton Button2;
private RadioButton Button3;
private RadioButton Button4;
private RadioButton Button5;
private RadioButton Button6;
private RadioButton Button7;
private RadioButton Button8;
private RadioButton Button9;
private RadioButton Button10;
private RadioButton Button11;
private RadioButton Button12;
/**
* Called when the activity is first created. Here we normally initialize
* our GUI.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button0 = (RadioButton) findViewById(R.id.Button0);
Button1 = (RadioButton) findViewById(R.id.Button1);
Button2 = (RadioButton) findViewById(R.id.Button2);
Button3 = (RadioButton) findViewById(R.id.Button3);
Button4 = (RadioButton) findViewById(R.id.Button4);
Button5 = (RadioButton) findViewById(R.id.Button5);
Button6 = (RadioButton) findViewById(R.id.Button6);
Button7 = (RadioButton) findViewById(R.id.Button7);
Button8 = (RadioButton) findViewById(R.id.Button8);
Button9 = (RadioButton) findViewById(R.id.Button9);
Button10 = (RadioButton) findViewById(R.id.Button10);
Button11 = (RadioButton) findViewById(R.id.Button11);
}

/**
* This is the thread on which all the IOIO activity happens. It will be run
* every time the application is resumed and aborted when it is paused. The
* method setup() will be called right after a connection with the IOIO has
* been established (which might happen several times!). Then, loop() will
* be called repetitively until the IOIO gets disconnected.
*/
class Looper extends BaseIOIOLooper {
/** The on-board LED and pins */
private DigitalOutput led_;
private DigitalOutput pin1;
private DigitalOutput pin2;
private DigitalOutput pin3;
private DigitalOutput pin4;
private DigitalOutput pin5;
private DigitalOutput pin6;
private DigitalOutput pin7;
private DigitalOutput pin8;
private DigitalOutput pin9;
private DigitalOutput pin10;
private DigitalOutput pin11;
private DigitalOutput pin12;
/**
* Called every time a connection with IOIO has been established.
* Typically used to open pins.
* @throws ConnectionLostException
*             When IOIO connection is lost.
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
*/
@Override
protected void setup() throws ConnectionLostException {
led_ = ioio_.openDigitalOutput(0, true);
pin1 = ioio_.openDigitalOutput(1, true);
pin2 = ioio_.openDigitalOutput(2, true);
pin3 = ioio_.openDigitalOutput(3, true);
pin4 = ioio_.openDigitalOutput(4, true);
pin5 = ioio_.openDigitalOutput(5, true);
pin6 = ioio_.openDigitalOutput(6, true);
pin7 = ioio_.openDigitalOutput(7, true);
pin8 = ioio_.openDigitalOutput(8, true);
pin9 = ioio_.openDigitalOutput(9, true);
pin10 = ioio_.openDigitalOutput(10, true);
pin11 = ioio_.openDigitalOutput(11, true);
pin12 = ioio_.openDigitalOutput(12, true);
}

/**
* Called repetitively while the IOIO is connected.
* @throws ConnectionLostException
*             When IOIO connection is lost.
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
*/
@Override
public void loop() throws ConnectionLostException {
led_.write(!Button11.isChecked());
pin1.write(Button1.isChecked());
pin2.write(Button2.isChecked());
pin3.write(Button3.isChecked());
pin4.write(Button4.isChecked());
pin5.write(Button5.isChecked());
pin6.write(Button6.isChecked());
pin7.write(Button7.isChecked());
pin8.write(Button8.isChecked());
pin9.write(Button9.isChecked());
pin10.write(Button10.isChecked());
pin11.write(Button11.isChecked());
pin12.write(Button12.isChecked());
            android:id="@+id/Button0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Low" />

        <RadioButton
            android:id="@+id/Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="High" />
    </RadioGroup><RadioGroup
        android:id="@+id/RadioGroup2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/radioGroup1"
        android:orientation="horizontal"
        android:layout_marginRight="15dp" >

        <TextView
            android:id="@+id/TextView2"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Passenger Seat"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/Button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/Button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Low" />

        <RadioButton
            android:id="@+id/Button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="High" />
    </RadioGroup>
    <RadioGroup
        android:id="@+id/RadioGroup3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/RadioGroup3"
        android:orientation="horizontal"
        android:layout_marginRight="15dp" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Daytime Running Lamps"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/Button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                        android:text="Off" />

        <RadioButton
            android:id="@+id/Button7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="On" />

   
    </RadioGroup>

    <RadioGroup
        android:id="@+id/RadioGroup4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/TextView4"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Drivers Mirror"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/Button8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/Button9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="On" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/RadioGroup5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/TextView5"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="Passenger Mirror"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/Button10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Off" />

        <RadioButton
            android:id="@+id/Button11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="On" />
    </RadioGroup>


</LinearLayout>

 
Reply all
Reply to author
Forward
0 new messages