我正尝试按如下方式自定义 View.onFocusChangeListener 类:
private class myCostBoxFocusListener implements View.onFocusChangeListener {
public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
//custom stuff here
}
}
然后我使用以下方式设置监听器:
costBox.setOnFocusChangeListener(new myCostBoxFocusListener());
//costBox is an EditText declared and instantiated earlier.
但是,为了创建类,我得到了编译器错误
"View.onFocusChangeListener cannot be resolved to a type"
设置监听器
"The method setOnFocusChangeListener(View.OnFocusChangeListener) in the type
View is not applicable for the arguments (OCRMain.myCostBoxFocusListener)"
//OCRMain is the name of the class I'm working in.
我在我的导入中导入了 android.view.View.OnFocusChangeListener,我真的不确定为什么会这样,因为我还为 EditText.OnEditorActionListener 创建了一个自定义类,没有错误。我尝试在 View.onFocusChangeListener 和 EditText.onFocusChangeListener 之间更改我的代码,但没有任何更改。我已尝试清理并重建项目,但不做任何更改。
非常感谢任何帮助。
最佳答案
答案很简单不是很好吗?感谢 Mike M. 的这个;我一直看到对“OnFocusChanged”的引用,坦率地说,我不完全确定其中的区别以及何时/为什么一个是合适的。如前所述,我还把第一个“o”的大写字母错误地小写了。但将其更改为以下有效:
private class myCostBoxFocusListener implements View.OnFocusChangeListener {
public void onFocusChange(View v, boolean hasFocus) {
//stuff
}
}
关于android - 尝试创建自定义 View.onFocusChangeListener 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27448874/