容量2GB!アクセス解析&動画ファイルも可能な無料ブログ。アフィリエイト完全対応。
  最新画像一覧   /    おもしろブログが満載! シャッフル ブログ  /     無料登録  

アンドロイドアプリ開発Key入力

  1. 2010/07/22(木) 12:16:28|
  2. android|
  3. トラックバック:1|
  4. コメント:0
KeyEventを試してみます。
Activityの onKeyDown , onKeyUp をOverrideします。
キーを押すとLogCatに表示されます。



public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_DPAD_CENTER){
Log.d("Test", "keyDown:DPAD_CENTER");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT){
Log.d("Test", "keyDown:DPAD_LEFT");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT){
Log.d("Test", "keyDown:DPAD_RIGHT");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_UP){
Log.d("Test", "keyDown:DPAD_UP");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){
Log.d("Test", "keyDown:DPAD_DOWN");
}

Log.d("Test", "KeyDown:keyCode="+keyCode);
return super.onKeyDown(keyCode,event);
}

@Override
public boolean onKeyUp(int keyCode,KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_DPAD_CENTER){
Log.d("Test", "keyUp:DPAD_CENTER");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT){
Log.d("Test", "keyUp:DPAD_LEFT");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT){
Log.d("Test", "keyUp:DPAD_RIGHT");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_UP){
Log.d("Test", "keyUp:DPAD_UP");
}else if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){
Log.d("Test", "keyUp:DPAD_DOWN");
}

Log.d("Test", "KeyUp:keyCode="+keyCode);
return super.onKeyDown(keyCode,event);
}
}


DTIブログって?