gpt4 book ai didi

java - 我正在做条形码扫描仪。但我可以在 TextView 中显示我的 resultCode 。

转载 作者:太空宇宙 更新时间:2023-11-04 10:59:34 25 4
gpt4 key购买 nike

我想显示ZXING的扫描结果。我将 ZXING 集成到我的 Android 应用程序中,扫描工作正常。现在我想在 TextView 中显示条形码编号结果。我在我的项目中使用 zxing 库。我设置了 result.setText(resultCode) 但它不起作用。这是我在教程中遵循的代码。

package com.example.norhanom.barcodeqrcode;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; //view button or textfield
import android.widget.Toast; //to show and create message for user,appears
as floating view over app
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import com.google.zxing.Result;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import me.dm7.barcodescanner.zxing.ZXingScannerView;


public class MainActivity extends AppCompatActivity {

private ZXingScannerView scannerView;
TextView result;
private ProgressDialog pd;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
result = (TextView)findViewById(R.id.textView1);
pd = new ProgressDialog(MainActivity.this);
pd.setMessage("loading");
pd.setCancelable(false);
pd.setCanceledOnTouchOutside(false);
}

public void scanCode(View view){

scannerView = new ZXingScannerView(this); // Programmatically initialize
the scanner view
scannerView.setResultHandler(new ZXingScannerResultHandler());

setContentView(scannerView); //Set the scanner view as the content view
scannerView.startCamera(); //scannerView open camera
}



@Override
public void onPause()
{
super.onPause();
scannerView.stopCamera(); //stop camera on pause
}

class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler
{

@Override
public void handleResult(Result result1)
{
String resultCode = result1.getText(); //get the result

Toast.makeText(MainActivity.this,resultCode,Toast.LENGTH_LONG).show();
//show result
setContentView(R.layout.activity_main);
scannerView.stopCamera(); //camera stop






}


}


}

最佳答案

下次使用setContentView后,您应该重新分配 View 。

//inside handleResult
setContentView(R.layout.activity_main);
result = (TextView)findViewById(R.id.textView1);
result.setText(resultCode);
scannerView.stopCamera();

关于java - 我正在做条形码扫描仪。但我可以在 TextView 中显示我的 resultCode 。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47047400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com