标签:android style blog http io color os sp java
李刚的Android疯狂讲义真是“疯狂”,浪费了3天时间,到底是他的代码有问题,还是怎么的不得而知。
public class MyButton extends Button
{
public MyButton(Context context , AttributeSet set)
{
super(context , set);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
super.onKeyDown(keyCode , event);
Log.v("-MyButton-" , "the onKeyDown in MyButton");
//返回false,表明并未完全处理该事件,该事件依然向外扩散
return false;
}
}
public class Propagation extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyButton bn = (MyButton)findViewById(R.id.bn);
//bn.setFocusable(true);
bn.requestFocus();
bn.setFocusableInTouchMode(true);
//为bn绑定事件监听器
bn.setOnKeyListener(new OnKeyListener()
{
@Override
public boolean onKey(View source
, int keyCode, KeyEvent event)
{
//只处理按下键的事件
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
Log.v("-Listener-" , "the onKeyDown in Listener");
}
// 返回false,表明该事件会向外传播
return false;
}
});
}
//重写onKeyDown方法,该方法可监听它所包含的所有组件的按键被按下事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
super.onKeyDown(keyCode , event);
Log.v("-Activity-" , "the onKeyDown in Activity");
//返回false,表明并未完全处理该事件,该事件依然向外扩散
return false;
}
}
标签:android style blog http io color os sp java
原文地址:http://www.cnblogs.com/fruitbolgs/p/4160862.html