I'm making an android app that reads a barcode. I saw a video on youtube that taught how to do and I replicated to be based and worked good. The problem was when I tried to put the return of the reading on a EditText
. In video , the result appears with Toast
. As much as I try, nothing appears in EditText
.
Follow the Java code:
package none.teste;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
import static none.teste.R.layout.activity_menu;
public class Menu extends AppCompatActivity implements ZXingScannerView.ResultHandler{
private ZXingScannerView leitorView;
EditText editCodigo;
Leitor l=new Leitor();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_menu);
editCodigo = (EditText) findViewById(R.id.editCodigo);
Toast.makeText(Menu.this,"onCreate",Toast.LENGTH_LONG).show();
}
public void LEITURA(View view) {
leitorView = new ZXingScannerView(this);
setContentView(leitorView);
leitorView.setResultHandler(this);
leitorView.startCamera();
Toast.makeText(Menu.this,"LEITURA",Toast.LENGTH_LONG).show();
}
@Override
protected void onPause() {
super.onPause();
leitorView.stopCamera();
Toast.makeText(Menu.this,"onPause",Toast.LENGTH_LONG).show();
}
@Override
public void handleResult(Result result) {
leitorView.stopCamera();
setContentView(R.layout.activity_menu);
l.setLido(result.getText().toString());
editCodigo.setText(l.getLido());
Toast.makeText(Menu.this,"handleResult",Toast.LENGTH_LONG).show();
leitorView.resumeCameraPreview(this);
}
@Override
protected void onResume() {
super.onResume();
Toast.makeText(Menu.this,"onResume",Toast.LENGTH_LONG).show();
}
}
These Toasts I put to know where the application was passing and the class Leitor
is bullshit, only has a String
attribute with getter and setter, does not need it.
Anyway, I wanted to pass the result to EditText
.