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