0

私のアプリでは、独自のボタンセットを使用してキーパッドを作成しましたが、いくつかの機能を使用して実際のキーパッドをシミュレートする必要があります。

ボタンは、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

コードの不適切な並べ替えで申し訳ありませんが、可能な限りコンパクトに保つ​​ようにしています。

ありがとう

4

1 に答える 1

1

以下のリンクを試してみてください。Androidのカスタムキーパッドに関する情報があります。

http://tutorials-android.blogspot.in/2011/06/create-your-own-custom-keyboard-for.html

また

Android用のソフトキーボードを開発するにはどうすればよいですか?

または

Androidのアプリ用に独自のキーボードを作成するにはどうすればよいですか?

見てください、私はそれがあなたを助けると思います。

于 2012-09-24T13:46:02.310 に答える