我正在片段中实现自定义键盘。我想将位于我的片段UI中的EditText的ResourceId发送到自定义键盘类。我在自定义键盘类中接收ResourceId时收到NullPointerException,这意味着不会发送Resourceid。
我实施的代码是:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_barcode_detail,
container, false);
inflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
editText_barcode = (EditText) rootView
.findViewById(R.id.editText_barcode);
mCustomKeyboard = new CustomKeyboard(mActivity, R.id.keyboardview,R.xml.hexkbd);
System.out.println("====inac====" + R.id.editText_barcode);
mCustomKeyboard.registerEditText(mActivity, R.id.editText_barcode);
return rootView;
}
自定义键盘类是:
class CustomKeyboard {
private KeyboardView mKeyboardView;
/** A link to the activity that hosts the {@link #mKeyboardView}. */
private Activity mHostActivity;
private EditText edittext;
public CustomKeyboard(Activity host, int viewid, int layoutid) {
mHostActivity= host;
mKeyboardView= (KeyboardView)mHostActivity.findViewById(viewid); //
Getting Resourceid successfully
mKeyboardView.setKeyboard(new Keyboard(mHostActivity, layoutid));
mKeyboardView.setPreviewEnabled(false);
mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
}
public void registerEditText( int resid) {
// Find the EditText 'resid'
System.out.println("======ed"+resid);
edittext= (EditText)mHostActivity.findViewById(resid);//
Not Getting Resourceid
}
答案 0 :(得分:0)
取而代之的是“R.id.editText_barcode” 发送'editText_barcode'对象EditText