我创建了一个自定义按钮,扩展了
这是我的代码:
事实上,当我点击我的自定义按钮时,什么也没发生...使用调试器,我可以看到该函数从未被调用。我不知道为什么。
那么,我是否忘记了一步?还有其他我错过的事情吗?
View
类,按照这个教程的说明:http://kahdev.wordpress.com/2008/09/13/making-a-custom-android-button-using-a-custom-view/
但是我有一个问题,onFocusChanged()
函数从未被调用。这是我的代码:
public class CustomButton extends View
{
...
public CustomButton(Context context, Car car)
{
super(context);
setFocusable(true);
setBackgroundColor(Color.BLACK);
setOnClickListener(listenerAdapter);
setClickable(true);
}
@Override
protected void onFocusChanged(boolean gainFocus, int direction,
Rect previouslyFocusedRect)
{
if (gainFocus == true)
{
this.setBackgroundColor(Color.rgb(255, 165, 0));
}
else
{
this.setBackgroundColor(Color.BLACK);
}
}
...
}
事实上,当我点击我的自定义按钮时,什么也没发生...使用调试器,我可以看到该函数从未被调用。我不知道为什么。
那么,我是否忘记了一步?还有其他我错过的事情吗?