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

Rog*_*ger 2 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;
    }

...
Run Code Online (Sandbox Code Playgroud)

但是后来当我想要做的时候

LinearLayout LinLayBg = (LinearLayout)findViewById(R.id.LL_total);
Run Code Online (Sandbox Code Playgroud)

它显示了用按钮填充它

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

有任何想法吗?谢谢!

Hou*_*ine 6

我认为你试图findViewById(int id);从一个非实例的View 调用该方法.

试试:

mInputView.findViewById(R.id.LL_total); 
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你