如何計算按鍵實時數?或通過按鍵? 這裏是我的代碼:如何計算Android中的按鍵實時數
public class MyActivity extends Activity implements View.OnClickListener, View.OnKeyListener {
/**
* Called when the activity is first created.
*/
EditText ed
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed=(EditText)findViewById(R.id.editText);
ed.setOnKeyListener(this);
}
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
keyCounter++;
Log.d("key","" + keyEvent.getKeyCode());
return super.onKeyUp(i, keyEvent) ;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_B:
keyCounter++;
return true;
}
return super.onKeyUp(keyCode, event);
}
}
我試用過的onkeyup和關鍵..但它沒有工作; I烘烤keyCounter的值,但仍爲零。任何人都知道如何在android中獲取按鍵的數量?謝謝。
Toast是來調試可怕的方式..有你sonsidered Log.d( 「標籤」, 「Soemthing」) –