How to send ListView contents to Sqlite database

半城伤御伤魂 提交于 2019-12-11 19:22:49

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/17486899/how-to-send-listview-contents-to-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!