We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have this looking everywhere for a simple way to write and edit text strings in android.
I tried using the controlP5 library, but does not affect the virtual keyboard keystrokes.
I think what I want can be done with editext, but my code does not work, any ideas?
import android.widget.EditText;
   import android.view.inputmethod.InputMethodManager;
    import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
    import android.view.KeyEvent;
    import android.view.View;
    import android.util.DisplayMetrics;
    import android.net.wifi.WifiInfo;
    import android.net.wifi.WifiManager;
   import android.content.Context;
   import android.content.pm.ActivityInfo;
   import android.content.SharedPreferences;
   import android.content.SharedPreferences.Editor;
  // EditText myEditText =  (EditText) findViewById(R.id.vnosEmaila);
import controlP5.*;
EditText txt1;
   InputMethodManager imm;
ControlP5 cp5;
String textValue = "";
String textValue2 = "";
void setup() {
 txt1 = (EditText)findViewById(R.id.text);
  size(700,400);
  PFont font = createFont("arial",20);
  cp5 = new ControlP5(this);
  cp5.addTextfield("input")
     .setPosition(20,100)
     .setSize(200,40)
     .setFont(font)
     .setFocus(true)
     .setColor(color(255,0,0))
     ;
  cp5.addTextfield("textValue")
     .setPosition(20,170)
     .setSize(200,40)
     .setFont(createFont("arial",20))
     .setAutoClear(false)
     ;
  cp5.addBang("clear")
     .setPosition(240,170)
     .setSize(80,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;    
  cp5.addTextfield("default")
     .setPosition(20,350)
     .setAutoClear(false)
     ;
  textFont(font);
}
void draw() {if(mousePressed == true){showVirtualKeyboard();delay(888);}
  background(0);
  fill(255);
try{textValue2 = txt1.getText().toString();  }catch(Exception e){}
//  if(key != 0){textValue=textValue+key;text(cp5.get(Textfield.class,"input").getText(), 360,130);key = 0;}
  text(textValue2, 360,180);//text(input, 460,180);
}
public void clear() {
  cp5.get(Textfield.class,"textValue").clear();
}
void controlEvent(ControlEvent theEvent) {
  if(theEvent.isAssignableFrom(Textfield.class)) {
    println("controlEvent: accessing a string from controller '"
            +theEvent.getName()+"': "
            +theEvent.getStringValue()
            );
  }
}
  public void showVirtualKeyboard() 
  {
    //LIMPIEZA     teclado_ON = 0; 
              InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    //    image(fondo, 0, 0);
  }
public void input(String theText) {
  // automatically receives results from controller input
  println("a textfield event for controller 'input' : "+theText);
}
greetings and thanks in advance
Answers
@anthony20====
this line cannot work: txt1 = (EditText)findViewById(R.id.text); if you want to work with that kind of code you have to use eclipse & pure android... simple way for editing text in processing is using apwidgets lib
Hi @Akenaton, Thanks so much.
I am testing apwidgets.
I need to know it: My android app is forced horizontal position. includes a search method through string that is updated every time it receives a keystroke. I use the key variable processing to gradually modify the string. this works great on a samsung galaxy ace and a tablet that I have. However, in a mini samsung galaxy detected only numeric keystrokes. When I try apwidgets I see is great and easier to use than direct control over the key variable. However, when jumping the keyboard in a horizontal position, the app no longer displayed.
greetings and thanks for showing me this great library
@anthony20===
as for beginning try to add orientation(LANDSCAPE) in setup() and in the manifest
@akenaton thanks for you answer
I tried that but it does not work. I want that when I click on the box, a normal keyboard appears. like when I use showVirtualKeyboard () i want it: keyboard type:
The problem is this keyboard that covers the application when it is working horizontal:
My app is designed on forced landscape mode.
when I use showVirtualKeyboard () I can not write about EditText box.
In short, I want the throwing editext in landscape mode, keyboard not cover my app.
I think this may be due to some library option that launches the keyboard in that mode. I'm trying somehow to deceive the library to report that the phone is vertical.
I fail, I thought the problem was the horizontallyScrolling variable, but I modified true and false and nothing has changed.
I found in the library code keyboard close, but not the "showVirtualKeyboard" I need to change.
great:) @Akenaton thanks for your help
After a whole day looking for information on the subject I found the solution here: http://stackoverflow.com/questions/4336762/disabling-the-fullscreen-editing-view-for-soft-keyboard-input-in-landscape
only is necesary changed:
for:
textField.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);right code:
Hi,@akenaton,
I have a new problem :(
Once built the textField box, is there effective way to hide it or delete it?
I see it: editText.setVisibility(View.INVISIBLE)
in the same situation i have created a button, added a listener and hideSoftInputFromWindow() behaviour...
Hi,@akenaton, I think I'm too noob to do that. Can you show me an example code?
Hi @akenaton,
I found an easier way to do that. Apparently I have found the solution to my problem. now I
just need to implement new concepts in my app. :) :) :D
it work:
Hide editext box.
widgetContainer.hide();Show editext box:
widgetContainer.show();hi anthony, if I tested your code in processing 3.0 I get some class not found errors. any quick hints?
thank you ks