I know similar questions have been asked before but I have searched and couldn't find a solution.
I am trying to setup barcodescanner as described here
public class MainFragment extends Fragment implements View.OnClickListener{
private ZXingScannerView scannerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_warrant, container, false);
ImageButton scanBar = (ImageButton) view.findViewById(R.id.scan_barcode);
scanBar.setOnClickListener(this);
Button checkImei = (Button) view.findViewById(R.id.btn_check);
checkImei.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.scan_barcode:
scannerView = new ZXingScannerView(getActivity());
scannerView.setResultHandler(new ZXingScannerResultHandler());
// setContentView(scannerView);
scannerView.startCamera();
break;
case R.id.btn_check:
Toast.makeText(getActivity(), "Button", Toast.LENGTH_SHORT).show();
break;
}
}
class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler {
@Override
public void handleResult(Result result) {
String resultCode = result.getText();
Toast.makeText(getActivity(), resultCode, Toast.LENGTH_LONG).show();
// setContentView(R.layout.activity_start);
scannerView.stopCamera();
}
}
}
Works in Activity but moving it in a fragment I get error with the setContentView. Is there an alternative to setContentView or may a different library that uses fragments?
This is the link of,
Official documentation
About how you can implement ZXingScanner into Fragment.
Cheers!