package com.basic;
import com.dhm.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class D_01 extends Activity{
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.d_01);
button = (Button)findViewById(R.id.D_01_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toastsow("按下了按钮键");
}
});
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
Toastsow("按下:上键");
break;
default:
break;
}
return super.onKeyUp(keyCode, event);
}
public void Toastsow(String str){
Toast.makeText(this, str,Toast.LENGTH_SHORT).show();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
Toastsow("弹起:上键");
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
int iAction = event.getAction();
if (iAction == MotionEvent.ACTION_CANCEL ||
iAction == MotionEvent.ACTION_DOWN ||
iAction == MotionEvent.ACTION_MOVE)
{
//ACTION_DOWN: 表示用户开始触摸.
//ACTION_MOVE: 表示用户在移动(手指或者其他)
//ACTION_UP:表示用户抬起了手指
return false;
}
int x = (int)event.getX();
int y =(int)event.getY();
Toastsow("触摸了什么位置"+Integer.toString(x)+"位置"+Integer.toString(y));
return super.onTouchEvent(event);
}
}