我正在尝试使用Zxing Scanner在我的应用程序中制作QR码扫描仪。但是,我使用片段而不是活动。我应该为mScannerView.setResultHandler(??????)添加什么参数。
我的按钮转到QR码扫描仪
FloatingActionButton add = (FloatingActionButton) view.findViewById(R.id.add_friend);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mScannerView = new ZXingScannerView(getActivity());
getActivity().setContentView(mScannerView);
mScannerView.setResultHandler(??????);
mScannerView.startCamera();
}
});
当我使用getActivity()和getContext()时出错。请帮助我......谢谢。
答案 0 :(得分:0)
mScannerView.setResultHandler(new ZXingScannerView.ResultHandler() {
@Override
public void handleResult(Result rawResult) {
Toast.makeText(getActivity(), "Contents = " + rawResult.getText() + ", Format = " + rawResult.getBarcodeFormat().toString(), Toast.LENGTH_SHORT).show();
}
});
或者只是实现它
public class ScannerFragment extends BaseFragment implements ZXingScannerView.ResultHandler {
@Override
public void handleResult(Result rawResult) {
Toast.makeText(getActivity(), "Contents = " + rawResult.getText() + ", Format = " + rawResult.getBarcodeFormat().toString(), Toast.LENGTH_SHORT).show();
}
}