开发者

findViewById won't work in InputMethodService, what do i do?

开发者 https://www.devze.com 2023-03-31 14:14 出处:网络
I\'m trying to create an android keyboard, this code works fine so far package keyboard.rob.com; import...

I'm trying to create an android keyboard, this code works fine so far

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;
    }

...

but later on when I'm trying to make

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

to populate it with buttons, it show

"*The method findViewById(int) is undefined for the type zyz *"

Any ideas? Thanks!


i think you are trying to call the method findViewById(int id); from a non instance of a View .

Try :

mInputView.findViewById(R.id.LL_total); 

hope it helps


You should be able to do it this way:

View.findViewById(R.id.LL_total);
0

精彩评论

暂无评论...
验证码 换一张
取 消