SmulianJulian
SmulianJulian

Reputation: 802

How to send ListView contents to Sqlite database

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,list);
setListAdapter(adapter);

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

And how I send to database from Activity B

public void addNewsale(View view) {
    HashMap<String, String> queryValues =  new  HashMap<String, String>();
    final TextView saleNotes =(TextView)findViewById(R.id.saleNotes);
    queryValues.put("saleNotes", saleNotes.getText().toString());
    controller.insertsale(queryValues);
    this.callHomeActivity(view);
}

The List is coming to Activity B in one row all together, In Activity A each row had an item. I do not know how to separate the ListViews Items. The problem is saleNotes can be 1 ListItem or 100 ListItems. I don't want to send information as a TextView because it will go in database as [4 cars 3 houses 1 banana] but instead I want

4 cars

3 houses

1 banana

Thank You OKS 16 This sends the information from Activity A to B correctly

ArrayList<String> al= new ArrayList<String>();
al = getIntent().getExtras().getStringArrayList("list");
if (al != null){
for(String item:al){
listItems.add(item);
}
adapter.notifyDataSetChanged();}

But how do I send to database? It's still a ListView.

Upvotes: 0

Views: 293

Answers (1)

oks16
oks16

Reputation: 1294

Try this:
for(String item:al){
listitems.add(item)
}

Upvotes: 1

Related Questions