I'm working on a QR scanner app. After a succesfull scan the scanned info goes into the alert box. From there, I need the info to go to an EditText field or skip the entire alert dialog. The result which has to go to the EditText is in the function below.
public class MainActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
EditText editText;
@SuppressLint("CutPasteId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText4);
EditText delete2;
Button button3;
button3 = findViewById(R.id.button3);
delete2 = findViewById(R.id.editText2);
final EditText finalEdittext = delete2;
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Clear EditText
finalEdittext.getText().clear();
}
});
EditText delete4;
Button button4;
delete4 = findViewById(R.id.editText4);
button4 = findViewById(R.id.button4);
final EditText finalEdittext1 = delete4;
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Clear EditText
finalEdittext1.getText().clear();
}
});
}
public void onClick(View v){
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
@Override
protected void onPause() {
super.onPause();
mScannerView.stopCamera();
}
@Override
public void handleResult(Result result) {
//handle result
Log.v("handleResult", result.getText());
//editText.setText(result.toString());
// editText.invalidate();
mScannerView.stopCamera(); //setContentView(R.layout.activity_main);
//resume scanning
//mScannerView.resumeCameraPreview(this);
updateScannerData(1,result.getText());
}
public void updateScannerData(int scanType, String scannedCode){
editText.setText(scannedCode);
//editText.invalidate();
//editText.requestLayout();
//finish();
//startActivity(getIntent());
this.recreate();
}
}
I only use one main activity and this is the XML of the EditText where the result has to go.
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="197dp"
android:ems="10"
android:hint="@string/scan_order"
android:inputType="textPersonName"
android:visibility="visible"
tools:backgroundTint="@android:color/holo_red_light" />
Any help is greatly appreciated. Thanks in advance.