DONE key

edited September 2014 in Android Mode

OSX10.6.8 P5 2.0.3, AVD

i have created 20 text Fields; and a button IME "Done" i have yo know if this button (or key) was pressed by user tried a lot of things == no success! (in the better case == null); what to do?

Tagged:

Answers

  • class IVB { // Modified Input Value Box, takes an almost string.
      color[] c= {
        color(128), color(0), color(196), color(255), color(0), color(255)
      };
      String s="";
      float x=0, y=0, w=100, h=20;//, v=0;
      boolean f=false;
      IVB() {
      }
      void onClick() {
        f=mouseX>=x&&mouseY>=y&&mouseX<=x+w&&mouseY<=y+h;
      }
      void onKey() {
        if (f) {
          if ( (key>='0'&&key<='9') || (key>='a'&&key<='z') || (key>='A'&&key<='Z') ) {
            s+=key;
            //v=float(s);
          }
          if (s.length()>0&&(key==DELETE||key==BACKSPACE)) {
            s=s.substring(0, s.length()-1);
            //v=float(s);
          }
        }
      }
      void draw() {
        pushStyle();
        stroke(f?c[3]:c[0]);
        fill(f?c[4]:c[1]);
        rect(x, y, w, h);
        fill(f?c[5]:c[2]);
        textAlign(LEFT, CENTER); // ,CENTER, CENTER);
        //text(s, x+(w/2), y+(h/2));
        text(s, x+5, y+(h/2));
        popStyle();
      }
    }
    
    IVB[] boxes = new IVB[11];
    
    void setup() {
      size(400, 400);
      for(int i=0;i<boxes.length;i++){
        boxes[i] = new IVB();
        boxes[i].x = 1;
        boxes[i].y = 2 + 22 * i;
        boxes[i].w = width-3;
      }
      boxes[boxes.length-1].s="DONE";
    }
    
    void draw() {
      background(0);
      for(int i=0;i<boxes.length;i++){
        boxes[i].draw();
      }    
    }
    
    void mousePressed(){
      for(int i=0;i<boxes.length;i++){
        boxes[i].onClick();
      }
      if(boxes[boxes.length-1].f){
        println("");
        for(int i=0;i<boxes.length-1;i++){
          println("" + i + " " + boxes[i].s);
          boxes[i].s="";
        }
        boxes[boxes.length-1].f = false;
      }
    }
    
    void keyPressed(){
      for(int i=0;i<boxes.length;i++){
        boxes[i].onKey();
      }
    }
    
  • dear tfGuy44, thanks for answering. i have tested; your code works very well and solves the problem but not the question. Your "boxes" are not android "textFields" as mine are, created with the APwidgets library and my question is how to capture the event fired by the done key or enter key. I can do that easily when i dont create any textfield ::

    import android.view.KeyEvent;
    
    int touche;
    String action;
    
    void setup(){
      orientation(PORTRAIT);
      fill(255,0,0);
    
    };
    
    void draw(){
    
    background(255);
    textSize(36);
    text(touche, 300,300); 
    println (touche);
    
    };
    
    @Override
            public boolean dispatchKeyEvent(KeyEvent event) {
              touche = event.getKeyCode();
    
                    return super.dispatchKeyEvent(event);
            }
    

    // BUT if i add some ApWidgets textField the dispatchKeyEvent remains allways nul except for menu or back buttons:::::

        import android.view.KeyEvent;
        import android.view.inputmethod.InputMethodManager;
        import android.text.InputType;
        import android.view.inputmethod.EditorInfo;
        import apwidgets.*;
    
        PWidgetContainer widgetContainer; 
        PEditText textField;
    
    
        int touche;
    
    
        void setup(){
          orientation(PORTRAIT);
          fill(255,0,0);
           widgetContainer = new PWidgetContainer(this); //create new container for widgets
          textField = new PEditText(20, 100, 150, 50); //create a textfield from x- and y-pos., width and height
          widgetContainer.addWidget(textField); //place textField in container
          textField.setInputType(InputType.TYPE_CLASS_TEXT);
          textField.setImeOptions(EditorInfo.IME_ACTION_DONE); //Done button instead of enter
          textField.setCloseImeOnDone(true);
    
        }
    
        void draw(){
        //text(code, 200,200);
        background(255);
        textSize(36);
        text(touche, 300,300); 
        println (touche);
    
    
        }
    
        @Override
                public boolean dispatchKeyEvent(KeyEvent event) {
                  touche = event.getKeyCode();
    
                        return super.dispatchKeyEvent(event);
                }
    
  • Your initial post was not helpful in allowing anyone to understand your problem.

    Your second post just might be.

  • dear TfGuy 34, Sorry, i apologize you are absolutely right, my question was too much condensed!!! - But i thought that speaking about "text fields" and IME-Done key meant using some GUI library, which are not common for android-pocessing...

  • and i see== nobody answered....

Sign In or Register to comment.