私のアプリでは、独自のボタンセットを使用してキーパッドを作成しましたが、いくつかの機能を使用して実際のキーパッドをシミュレートする必要があります。
ボタンは、xmlのテーブルレイアウトで描画されます。
フォーカスを次の編集テキストに移動するには、次のボタンをシミュレートする必要があります。編集テキストは、ページ上の配列として処理されます。
また、カーソルが現在ポイントされている場所にキーを追加するAndroidの実際のキーボードの入力をシミュレートする必要があります。現在、キーは文字列の後ろから追加/置換/削除されEditText
ます。
キーパッドボタンは配列として処理されます。
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
コードの不適切な並べ替えで申し訳ありませんが、可能な限りコンパクトに保つようにしています。
ありがとう