-1
I’m making an android app that reads a barcode. I saw a video on Youtube that taught how to do and replicated to take as a basis and worked well. The problem was when I tried to put the read return on a EditText. In the video, the result appears with Toast. No matter how hard I try, there’s nothing on 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 going and the class Leitor It’s bullshit, it only has one attribute String with getter and Setter, you don’t need that.
Anyway, I wanted to pass the result to the EditText.
Sometimes we’ll make silly mistakes. You made sure
result.getText().toString()returns something?– Natan
In fact the solution may be exactly there, the text being informed in
editCodigo.setText(l.getLido());comes fromresult.getText().toString(). He said that the result appears in Toast, but in fact only this here:Toast.makeText(Menu.this,"handleResult",Toast.LENGTH_LONG).show();.Surely you should check if Result in the methodhandleResultis not coming empty.– Natan
Natan, I made sure yes, when I put -> Toast.makeText(Menu.this,result.gettext(),Toast.LENGTH_LONG). s how(); works well, but the problem is that it only works with Toast, when I try to put in Edit with setText this is blank, IE, has a return, but for some reason the business does not appear. Note that if I put setText with anything else, like editCodigo.setText("TEST"); TEST appears in the field. Thanks anyway. : ) I think the problem is in the return to activity_menu, but I’m not sure. I’ll see if I can fix it agr. If you know something says there
– J.Young
Glr, I solved my problem. The error was related to Activity msm, I have to tinker with the manifest and other things. Thank you all!!!
– J.Young