For my app I've made a keypad with its own set of buttons however I need to simulate the actual keypad with a few functions.
The buttons are drawn in a tablelayout in xml.
I need to simulate the next button to move the focus to the next edit text. The edit texts are handled as an array on the page.
I also need to simulate the typing of android's actual keyboard where it will add the key where the cursor is currently pointed at. Currently the keys will add/replace/remove from the back of the EditText
string.
The keypad buttons are handled as an array.
public void onClick(View v) {
try {
String tmp=texts[selectEdit].getText().toString();
switch (n) {
case 3: texts[selectEdit].setText(tmp.substring(0,tmp.length()-1));
break;//get cursor position and delete char
case 7:{
Precision.performClick();
break;
}//spinner for selecting precision
case 11:{
if(!tmp.contains("E"))
texts[selectEdit].setText(tmp+""+keybuttons[n].getText());
break;
}//check for E if dont have do default case
case 15:{
//calculator.num=n;
//startActivity(new Intent("com.easyPhys.start.calculator"));
break;
}//open Calculator
case 16: break;//next field
case 17: {
onBackPressed();
break;
}//simulate back button
default:{
texts[selectEdit].setText(tmp+""+keybuttons[n].getText());
//get cursor start and end and get entire String
// replace selected String with button text
//insert back
break;
}
}//end of switch
}//end of try
Sorry for the improper sorting of code but I've tried to keep it as compact as possible.
Thanks