Search code examples
androidarraylistandroid-arrayadapterlistviewitem

Separting ListItems in next Activity


I am passing ListItems in an ArrayList to another activity. On the next Activity the ListItems are all together on one row. The first activity can send 1 ListItem or many, many ListItems. I am going to send the ListItems in the second activity to a database. They all go into same column in the database but their values must be separated. How do I separate the ListItems so that when they go into the database EACH one (not the combined value of the list)can be retrieved later.

ACTIVITY A

adapter=new ArrayAdapter<String>(this,
    R.layout.salelistitems,R.id.saleNotes,listItems);
    setListAdapter(adapter);

This part is working fine, just showing that I sent

.putStringArrayListExtra("list", listItems);

ACTIVITY B

adapter=new ArrayAdapter<String>(this,
    R.layout.salelistitems,R.id.saleNotes,listItems);
    setListAdapter(adapter);

    ArrayList<String> al= new ArrayList<String>();
    al = getIntent().getExtras().getStringArrayList("listItems");
    if (al != null) 
    {
    listItems.add(al+"");
    adapter.notifyDataSetChanged();

I am sending numbers and I don't want the value (1,2,3,4) entered into the database I want the values

1 (to database column)

2 (to database column)

3 (to database column)

4 (to database column)

I hope that makes it clear. Thanks


Solution

  • String[] items = al.split(",");