简体   繁体   中英

lines not being called out

hi i encountered this problem where some out my line are not being called as i debugged the lines alrd

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
                IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
                if (result.getContents() != null) {
                    String scanContent = result.getContents();
                String scanFormat = result.getFormatName();

                // display it on screen
                formatTxt.setText("FORMAT: " + scanFormat);
                contentTxt.setText("CONTENT: " + scanContent);
            }else {
                Toast toast = Toast.makeText(getContext(),"No scan data received!", Toast.LENGTH_SHORT);
                toast.show();
            }
        }

}

the onactivityresult is not being called out how do i rectify this?

heres the full code

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

/**
 * Created by P1422160 on 3/1/2017.
 */


public class ThreeFragment extends Fragment{

    public ThreeFragment() {
        // Required empty public constructor
    }

    Button scan_btn;
    EditText Edit_current;
    TextView formatTxt, contentTxt;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle   savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
        scan_btn = (Button) view.findViewById(R.id.scan_button);
        //initialize the textViews
        formatTxt = (TextView) view.findViewById(R.id.scan_format);
        contentTxt = (TextView) view.findViewById(R.id.scan_content);
        final Activity activity = getActivity();
        scan_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IntentIntegrator integrator = new IntentIntegrator(activity);
                integrator.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);
                integrator.setPrompt("Scan");
                integrator.setCameraId(0);
                integrator.setBeepEnabled(false);
                integrator.setBarcodeImageEnabled(true);
                integrator.initiateScan();
            }
        });

        return view;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result.getContents() != null) {
            String scanContent = result.getContents();
            String scanFormat = result.getFormatName();

            // display it on screen
            formatTxt.setText("FORMAT: " + scanFormat);
            contentTxt.setText("CONTENT: " + scanContent);
        }else {
            Toast toast = Toast.makeText(getContext(),"No scan data received!", Toast.LENGTH_SHORT);
            toast.show();
        }}}

xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".HomeActivity">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="scan"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:id="@+id/btn_scan_now" />

<TextView
    android:id="@+id/scan_format"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textIsSelectable="true"
    android:layout_below="@+id/btn_scan_now"
    android:gravity="center_horizontal"
    android:layout_marginBottom="@dimen/activity_vertical_margin" />
<TextView
    android:id="@+id/scan_content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textIsSelectable="true"
    android:layout_below="@+id/scan_format"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:gravity="center_horizontal" />

this activity is suppose to scan a barcode and display its format and content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM