java - findViewById 在 InputMethodService 中不起作用,我该怎么办?

标签 java android

我正在尝试创建一个 android 键盘,这段代码到目前为止工作正常

package keyboard.rob.com;

import...

public class xyz extends InputMethodService 
implements KeyboardView.OnKeyboardActionListener {

    private LinearLayout mInputView;

    @Override public View onCreateInputView() {
        mInputView = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null);
        return mInputView;
    }

...

但稍后当我尝试制作

LinearLayout LinLayBg = (LinearLayout)findViewById(R.id.LL_total);

用按钮填充它,它显示

“*方法 findViewById(int) 未定义类型 zyz *”

有什么想法吗?谢谢!

最佳答案

我认为您正在尝试从 View 的非实例调用方法 findViewById(int id);

尝试:

mInputView.findViewById(R.id.LL_total); 

希望对你有帮助

关于java - findViewById 在 InputMethodService 中不起作用,我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7244172/

相关文章:

java - 在 Spring Boot 中更改了 Rest Service 输入参数

java - Stream<Employee> 类型中的方法 filter(Predicate<? super Employee>) 不适用于参数 ((<no type> e) -> {})

java - 高效的缓存同步

java - 出现错误 : java. sql.SQLException:结果集开始之前

Java 8 流 "ifPresent"

android - 在 FragmentStatePagerAdapter 的 instantiateItem() 中实现 setTag() 和 findViewWithTag()

Android Studio 0.8.0 错误 :The SDK Build Tools revision (19. 0.3) 对于项目 XXX 来说太低了。最低要求是 19.1.0

android - 如何让所有包只显示在应用程序屏幕中

android - 为什么 AlertDialog.Builder 没有 setOnDismissListener 或 setOnShowListener 方法?

android - 我的 AndroidManifest.xml 有什么问题?语法错误?