Hi, I have now started following this guide https://github.com/mbientlab/MetaWear-Tutorial-Android/tree/master/starterand I am stuck on the stage where I should_ "Override onViewCreated to have the switch control the led with an OnCheckChangedListener class:"_. I have added the button to the layout and debugging works. I just dont know where should add the onclicklistener. When I add the text to the "DeviceSetupActivityFragment" I get lots off red errors.

Where should and how should I add the code?

Thank you very much


  • edited March 2018

    I can not find the onViewCreated function. But if I add it below onCreate I keep getting error on "setOnCheckedChangeListener".

  • What errors are outputted when you compile the code?

    Please post the actual code, not screen shots of it.

  • edited March 2018

    will post in a minute

  • Information:Gradle tasks [:starter:assembleDebug]
    Error:(56, 8) error: DeviceSetupActivityFragment is not abstract and does not override abstract method onServiceConnected(ComponentName,IBinder) in ServiceConnection
    Error:(99, 52) error: cannot find symbol method setOnCheckedChangeListener((buttonVie[...]; } })
    Error:Execution failed for task ':starter:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

    Information:BUILD FAILED in 1s
    Information:3 errors
    Information:0 warnings
    Information:See complete output in console

  • Oh sorry, I named the txt. files by opposite names! But I hope that you can find what's wrong.
    Thank you very much Eric.

  • As the error message says, you do not have onServiceConnected defined; this function is present in the original file.

    Regarding the switch issue, the example code is using the Android switch widget, not MetaMotion's push button switch. It looks like you are importing the wrong Switch class.

  • Thank you a thousand times!! - It's all clear for me now. I have a working switch now!
    May the force be with you.

This discussion has been closed.