im work in a application capture a bar code and I want to show in the list, but the problem I have is that the captured data not shown in the list and not every time you captured with the button add new barcode captured.
Thanks for help
public class MainActivity extends 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();
}
}
}
You need to add the data to an
Adapter, then refresh theListViewby callingnotifyDataSetChanged()on theAdapterandinvalidate()on theListView.