EDGE button

HI,

For EDGE devices with touch screen....

We are developing a data field and we would like to add a button on screen to show certain info via pop up. Is it possible?

Thanks in advance,

  • thanks a lot, but I think I too dumb I put this onUpdate and does not work, do I have to do something else?


    it shows me this error



    		if(val) {
    		Model = 1;
    		}else{
    		Model = 2;
    		}

  • Ok I have this working

    	class InputDelegate extends Ui.BehaviorDelegate {
    	function onTap(evt) {
    		var val = !val;
        	Ui.requestUpdate();
        	return true;
        }
        }
        
        function initialize() {
            DataField.initialize();
            BehaviorDelegate.initialize();
            }
            
        function onUpdate(dc) {
    
    		if(val == true) {
    		Model = 1;
    		}else{
    		Model = 2;
    		}


    but val is not detected

    Undefined symbol ':val' detected.
    BUILD: Complete

  • if you want val to be in your input delegate, after line  1 for what you posted, add

    var val=false; //or =true;, depending on what you want the default to be.

  • no, it does not work it says it also does not work if you put var val = true; inside: class AppView extends Ui.DataField {

    Cannot find symbol ':val' on type 'self' on the line 16.

    the problem I 
    think it's inside onUpdate

  • no it think it's not posible get out a variable to onUpdate I also tried to call with a delegate .mc  this way but it says

    Undefined symbol ':val' detected.


    using Toybox.WatchUi;
    
    class AppDataFieldDelegate extends WatchUi.BehaviorDelegate {
      function initialize() {
        BehaviorDelegate.initialize();
      }
    
      function onTap(event) {
        var val = true;
        WatchUi.requestUpdate();
        return true;
      } 
    }

            class AppView extends Ui.DataField {
            
            var del = new AppDataFieldDelegate();
            }
    
            function onUpdate(dc) {
    		if(del.val) {
    		Model = 1;
    		}else{
    		Model = 2;
    		}
    		}

  • In getInitial view, bothe the view and delegate are created.  What you can do is pass the view to the delegate (or v/v) like this:

    function getInitialView() {

      var view=new MyView();

      return [view,MyDelegate(view)];

    }

    in your delegate, ininialize will have the view as a parameter

    class MyDelegate extends WatchUi.BehaviorDelegate {
      var view;
      function initialize(v) {
        BehaviorDelegate.initialize();
        view=v;
      }
      
      function onTap(evt) {
        view.val=!view.val;
        WatchUi.requestUpdate();
        return true;
      }
    }

    var val is then in your view class, but it's changed in the delegate.

  • Thanks a lot Jim really thanks for your patience now it works with the get initial view trick, really thanks

  • if I wish to this onKey what should I do I think this is not ok

        function onKey(evt) {
        	var key=evt.getKey();
    	if(key==WatchUi.KEY_ENTER) {
       	val = !val;
       	}
       	WatchUi.requestUpdate();
    	return true;
    	}
    	}