User Input for Android Phone

edited February 2015 in Android Mode

I am writing an Android phone app that requires user input. I simply want to enter a number in two fields. Make some calculations and print to two output fields. I cannot seem to get started on how to get user input. Seems like it should be simple. It is in other languages I am familiar with. Processing is new to me and I just can't get the input.

Tagged:

Comments

  • edited February 2015

    A pity Processing devs don't see a need to include user's typed in input in its official API. :(
    Dunno about Android but, in Java, I'd use JOptionPane for some dirty & quick solution: *-:)
    https://docs.oracle.com/javase/8/docs/api/javax/swing/JOptionPane.html

    /** 
     * No Repeat ID Input (v1.10)
     * by GoToLoop (2013/Nov)
     * 
     * forum.processing.org/two/discussion/869/
     * check-array-contents-with-arraylist
     */
    
    import static javax.swing.JOptionPane.*;
    
    final StringList ids = new StringList( new String[] {
      "Eric", "Beth", "Katniss"
    } );
    
    void draw() {
      println(ids);
    
      final String id = showInputDialog("Please enter new ID");
    
      if (id == null)   exit();
    
      else if ("".equals(id))
        showMessageDialog(null, "Empty ID Input!!!", 
        "Alert", ERROR_MESSAGE);
    
      else if (ids.hasValue(id))
        showMessageDialog(null, "ID \"" + id + "\" exists already!!!", 
        "Alert", ERROR_MESSAGE);
    
      else {
        showMessageDialog(null, "ID \"" + id + "\" successfully added!!!", 
        "Info", INFORMATION_MESSAGE);
    
        ids.append(id);
      }
    }
    
  • edited February 2015

    Moved to Android category where you are more likely to get answers...

  • @ PhiLo :: yes, because javax.swing.JOptionPane.* with android... so : you can create an editText (you can do that easily with APWidgets lib) create also some done button (to tell when user considers that everything == ok then from the field created get the text entered by user with .getText() then apply the same "compare methods" than PhiLo (or simplifying because its StringList with "pure android" will not work, so create a standard arrayList) then instead of showMessageDialog() make a switch and a toast message, like in a login.

Sign In or Register to comment.