无法在Fragment中实现ContentView

时间:2017-08-04 20:18:39

标签: java android linuxmint

我想将ZXingscanner设置为片段内的内容视图,但它不起作用。我有一些选项卡的应用程序和其中一个选项卡我希望有这个ZXingscanner视图,但当我尝试设置它不起作用。没有任何setContentView片段或类似的东西适用于此特定案件 ?此外,警报对话框构建器显示错误,它说警告对话框不能应用于片段。任何帮助将非常有帮助。 这是代码:

package com.hist_area.imeda.histarea.fragment;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.Toast;

import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;


public class EmptyFragment extends Fragment implements ZXingScannerView.ResultHandler {
    public static EmptyFragment create() {
        return new EmptyFragment();
    }
    Vibrator vibrator;

    private static final int CAMERA_PERMISSION_REQUEST_CODE = 8675309;
    private ZXingScannerView mScannerView;

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                invokecamera();
            }
        }
    }
        public void invokecamera() {
            mScannerView = new ZXingScannerView(this);
            return View(mScannerView);
            mScannerView.setResultHandler(this);
            mScannerView.startCamera();
        }
    @Override
    public void handleResult(Result result) {
        vibrator.vibrate(369);
        Log.w("handleResult", result.getText());
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("             Scan Result");
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mScannerView.resumeCameraPreview(EmptyFragment.this);
            }
        });

        invokecamera();

        builder.setMessage(result.getText());
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }



}

0 个答案:

没有答案