我将QRCodeReaderView的使用从Activity转换为Fragments,我遇到了问题。我将活动移动到swipeview正在调用的以下片段。 这是代码:
public class MainBusinessFragment extends Fragment implements QRCodeReaderView.OnQRCodeReadListener {
RoyalPoints points = new RoyalPoints();
private QRCodeReaderView mydecoderview;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View myView = inflater.inflate(
R.layout.fragment_main_business, container, false);
mydecoderview = (QRCodeReaderView) myView.findViewById(R.id.qrdecoderview);
mydecoderview.setOnQRCodeReadListener(this);
return myView;
}
// Called when a QR is decoded
// "text" : the text encoded in QR
// "points" : points where QR control points are placed
@Override
public void onQRCodeRead(String text, PointF[] points) {
final String user = text;
ImageView clicker = (ImageView) getActivity().findViewById(R.id.clicker);
clicker.setVisibility(View.VISIBLE);
clicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addPoints(user);
}
});
}
private void addPoints(String user) {
points.setPoints(10);
points.setUser(user);
points.setBusiness(ParseUser.getCurrentUser());
points.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Toast.makeText(getActivity(), "10 Points added", Toast.LENGTH_SHORT).show();
}
});
}
我遇到以下错误,无法继续前进(“java.lang.ClassCastException:com.ilias.royal.MainBusinessFragment无法转换为android.app.Activity”)。 非常感谢任何帮助,谢谢。