如何在片段中调用setContentView [英] How to call setContentView in a fragment
本文介绍了如何在片段中调用setContentView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道之前也曾问过类似的问题,但我已经搜索过并且找不到解决方法.
I know similar questions have been asked before but I have searched and couldn't find a solution.
我试图按照此处
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();
}
}
}
可在Activity中工作,但将其移动成一个片段,则setContentView会出错.是否可以使用setContentView替代,或者可以使用片段的其他库?
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.
干杯!
这篇关于如何在片段中调用setContentView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文