Reputation:
I'm trying to make a QR Code Scanner in my application using Zxing Scanner. However, i'm using fragment instead of activity. What parameter should i put to mScannerView.setResultHandler(??????).
My Button to go to QR Code Scanner
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();
}
});
There is error when i use getActivity() and getContext().Kindly Help me..Thanks.
Upvotes: 1
Views: 2405
Reputation: 9117
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();
}
});
or just implement it
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();
}
}
Upvotes: 1