2017-01-11 18 views
0

私が作成しているこのネイティブ点字アプリには、6つの異なるボタンがあり、私はすべてのユニークな組み合わせが私に別の文字を持って来たいと思っています。Android:タイマーの入力を処理してTextviewに設定する

たとえば、ボタン1を押すと簡単に文字「A」が表示されます。その後、ボタン1とボタン2を押すと、文字「C」が表示されます。私はこれらの6つのボタンのすべての異なるボタンの組み合わせが私に別個の手紙をもたらすことを望む。


processInput()に私はmapを開始したが、私はボタンをクリックしようとしたとき

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.keyboard); 

     Window window = this.getWindow(); 
     window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); 
     window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); 
     window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON); 

     // Init GUI 
     txtMessage = (EditText) findViewById(R.id.txtMesssage); 
     Button buttonOne = (Button) findViewById(R.id.block1); 
     Button buttonTwo = (Button) findViewById(R.id.block2); 
     Button buttonThree = (Button) findViewById(R.id.block3); 
     Button buttonFour = (Button) findViewById(R.id.block4); 
     Button buttonFive = (Button) findViewById(R.id.block5); 
     Button buttonSix = (Button) findViewById(R.id.block6); 



     // Attached Click Listener 
     btnSend.setOnClickListener(this); 

     buttonOne.setOnClickListener(this); 
     buttonTwo.setOnClickListener(this); 
     buttonThree.setOnClickListener(this); 
     buttonFour.setOnClickListener(this); 
     buttonFive.setOnClickListener(this); 
     buttonSix.setOnClickListener(this); 

} 

@Override 
public void onClick(View v) { 

    final Map<String, String> map = new HashMap<String, String>(); 

     Timer processTimer = new Timer(); 

     processTimer.schedule(new TimerTask() { 
      public void run() {  
       processInput();  
      } 

      private void processInput() { 
       // TODO Auto-generated method stub 
       map.put(getString(R.id.block1), "A"); 
       map.put(getString(R.id.block1) + getString(R.id.block2), "C"); 

       map.get(R.id.block1); 
       map.get(R.id.block1+R.id.block2); 

      } 
     }, 500); // Delay before processing. 

    processTimer.cancel(); 

    processTimer.schedule(new TimerTask() { 
      public void run() {  
       processInput();  
      } 

      private void processInput() { 
       // TODO Auto-generated method stub 


      } 
     }, 500); 
} 

XMLレイアウト "アプリが自動的に停止":

enter image description here

私がように見えることはできませんがそれを取得すると、私はTimerでエラーが発生しています。

Logcatエラー:

01-12 21:43:09.764: E/AndroidRuntime(20677): FATAL EXCEPTION: main 
01-12 21:43:09.764: E/AndroidRuntime(20677): Process: info.androidhive.speechtotext, PID: 20677 
01-12 21:43:09.764: E/AndroidRuntime(20677): java.lang.IllegalStateException: Timer was canceled 
01-12 21:43:09.764: E/AndroidRuntime(20677): at java.util.Timer.scheduleImpl(Timer.java:558) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at java.util.Timer.schedule(Timer.java:456) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at info.androidhive.speechtotext.Braillekeyboard.onClick(Braillekeyboard.java:307) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at android.view.View.performClick(View.java:5225) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at android.view.View$PerformClick.run(View.java:21195) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at android.os.Handler.handleCallback(Handler.java:739) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at android.os.Handler.dispatchMessage(Handler.java:95) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at android.os.Looper.loop(Looper.java:148) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at android.app.ActivityThread.main(ActivityThread.java:5451) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at java.lang.reflect.Method.invoke(Native Method) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
01-12 21:43:09.764: E/AndroidRuntime(20677): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

元のコード:

Timer processTimer = new Timer().schedule(new TimerTask() { 
    public void run() { processInput(); } 
}, 500); // Delay before processing. 


processTimer.cancel(); 
processtimer.schedule(new TimerTask() { 
     public void run() { processInput(); } 
    }, 500); 
+0

'logcat'の例外スタックトレースを投稿してください。 –

+0

@ KarsenGaussありがとうございました。 – pjforum

答えて

0

あなたはcancelledタイマーにschedule()しようとしています。 documentationによれば、キャンセルされたタイマーは再び使用できません。新しいインスタンスが必要です。

+0

こんにちは、私は何をしていますか? – pjforum

+0

@pjforumなぜschedule()への2回目の呼び出しが必要ですか? –

+0

私は上記のオリジナルコードを編集しました。それはそうなるはずですが、いくつかのエラーが発生しているので、変更してコードを追加しました。私の修正は間違っていたのですか? – pjforum

関連する問題