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

时间:2011-08-30 13:44:15

标签: 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 *”

有什么想法吗?谢谢!

2 个答案:

答案 0 :(得分:6)

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

尝试:

mInputView.findViewById(R.id.LL_total); 

希望有所帮助

答案 1 :(得分:3)

你应该能够这样做:

View.findViewById(R.id.LL_total);