0

我在一个应用程序中工作,捕获一个条形码,我想在列表中显示,但我遇到的问题是捕获的数据未显示在列表中,并且不是每次使用按钮捕获时都会添加捕获的新条形码。感谢帮助

公共类 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();
          }

        }   
}
4

1 回答 1

0

您需要将数据添加到,然后通过调用和Adapter刷新。ListViewnotifyDataSetChanged()Adapterinvalidate()ListView

于 2013-01-25T14:28:04.643 回答