我在一个应用程序中工作,捕获一个条形码,我想在列表中显示,但我遇到的问题是捕获的数据未显示在列表中,并且不是每次使用按钮捕获时都会添加捕获的新条形码。感谢帮助
公共类 MainActivity 扩展 Activity {
String barcode;
ListView ListaBarCode;
ListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListaBarCode = (ListView) findViewById( R.id.lvCodigoDeBarra);
if(barcode == null)
{
//do nothing
}else
{
String [] codigosDeBarra = new String[] {barcode};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, codigosDeBarra);
ListaBarCode.setAdapter(adapter);
}
}
public void btnScanner(View view)
{
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
barcode = scanResult.getContents();
}
}
}