I have my arraylist taking my data from my sqlite database, when i deleted the data inside the sqlitedatabase i want to refresh the list i did this but it crash:
SQLiteDatabase db;
ListView lv;
ArrayList<String> your_array_list = new ArrayList<String>();
ArrayAdapter<String> arrayAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_historique);
db=openOrCreateDatabase("Site2", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS story2(_id INTEGER PRIMARY KEY,adresse VARCHAR);");
Cursor cursor = db.rawQuery("select * from story2",null);
lv = (ListView) findViewById(R.id.listView);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
long clic= id+1;
Cursor c2 = db.rawQuery("SELECT * FROM story2 where _id="+clic+"", null);
if (c2.moveToFirst()){
do{
String site =c2.getString(1);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(site));
startActivity(browserIntent);
}while(c2.moveToNext());
}
c2.close();
}
});
// Instanciating an array list (you don't need to do this,
// you already have yours).
List<String> your_array_list = new ArrayList<String>();
// This is the array adapter, it takes the context of the activity as a
// first parameter, the type of list view as a second parameter and your
// array as a third parameter.
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
your_array_list );
lv.setAdapter(arrayAdapter);
if(cursor.moveToFirst())
{
do {
your_array_list.add(cursor.getString(1));
} while (cursor.moveToNext());
}cursor.close();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_historique, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
db.execSQL("DELETE FROM story2");
arrayAdapter.notifyDataSetChanged();
return true;
}
return super.onOptionsItemSelected(item);
}
}
i think it's because i'am refreshing the adapter but i didn't do anything to it
If you want to refresh your ArrayAdapter after you've deleted the underlying data set, you can call
arrayAdapter.clear();
Then you don't have to call
arrayAdapter.notifyDataSetChanged();
Related
I want to populate spinner from sqlite database. After I am retrieving the relevant data it showed junk values. Could you please help me to fix this. I will attach my codes here.
--java File--
public class AddNewMovieActivity extends AppCompatActivity {
private Spinner movieTypes;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_new_movie);
movieTypes = (Spinner) findViewById(R.id.spinMovieType);
loadSpinnerData();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_add_new_movie, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void loadSpinnerData() {
// database handler
DBHelper db = new DBHelper(this);
// Spinner Drop down elements
List<MovieType> lables = db.getAllMovieTypes();
// Creating adapter for spinner
ArrayAdapter<MovieType> dataAdapter = new ArrayAdapter<MovieType>(this,android.R.layout.simple_spinner_item,lables);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
movieTypes.setAdapter(dataAdapter);
}
}
-- DBHelper--
public List<MovieType> getAllMovieTypes() {
SQLiteDatabase db = getReadableDatabase();
List<MovieType> lst = new ArrayList<MovieType>();
Cursor cursor = db.query(TABLE_MOVIE_TYPE, null, COLUMN_STATUS + "=?", new String[]{"A"}, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()){
String type = cursor.getString(1).toString();
MovieType movieType = new MovieType(type);
movieType.setTypeId(cursor.getInt(0));
lst.add(movieType);
cursor.moveToNext();
}
}
db.close();
return lst;
}
I just want to show the movie types from the database. Please help me. this code returns the object values. but I need the string value of it. I have tried to convert my object to string. but I couldn't find a proper way to fix it. Actually I am very new to Android. so please help me.
What you can do is to Override toString() method in your MovieType class
public class MovieType{
//Whatever fields you have here
//Override toString()
#Override
public String toString() {
return your_field_name;
/***put the field name which you want to show in spinner
Or
You can append multiple fileds
return field1 + field2+......;
***/
}
}
And your all set, you would then see the value of the field in your spinner, what you have set in toString() method.
You can make custom adapter or you can make your list of String type.
As you have mentioned that you just want to show movies type. You can do this in your getAllMovieTypes() function.
public List<String> getAllMovieTypes() {
SQLiteDatabase db = getReadableDatabase();
List<String> lst = new ArrayList<String>();
Cursor cursor = db.query(TABLE_MOVIE_TYPE, null, COLUMN_STATUS + "=?", new String[]{"A"}, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()){
String type = cursor.getString(1).toString();
lst.add(type);
cursor.moveToNext();
}
}
db.close();
return lst;
}
Now, you can display only type.
I have an activity which has a spinner to select a day and a list that should show the list items according to the item selected from the spinner.
I'm querying the sqlite database and different queries must be used for different items selected on spinner.
I'm using a simple cursor adapter.
I have set onItemSelected(AdapterView<?> parent, View view, int position, long id) for my spinner. In that I check if the selected spinner item equals to today.
If so I need to change the list that is shown.
My problem is that the list stays the same no matter what spinner item is selected. It doesn't change.
Note that my spinner and the list are on same page. Can someone please suggest a solution for this?
public class RecentJobListActivity extends Activity {
ListView listView ;
private Spinner spinner;
private TakenJobDataBaseOpenHelper jobDatabaseHelper;
private Cursor cursor;
SimpleCursorAdapter cursoradapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recent_job_list);
addItemsOnSpinner();
//This is the database helper class
jobDatabaseHelper = new TakenJobDataBaseOpenHelper(this);
String[] fromColumns = {TakenJobDataBaseOpenHelper.TAKENJOBS_COLUMN_RequestID,TakenJobDataBaseOpenHelper.TAKENJOBS_COLUMN_Destination,TakenJobDataBaseOpenHelper.TAKENJOBS_COLUMN_CustomerName};
int[] toViews = {R.id.singleRequestID, R.id.singleDestination,R.id.singleCustomerName};
//when the page first loads the result of queru getAlljobs() will be shown.this works
cursor = jobDatabaseHelper.getAllJobs();
cursoradapter = new SimpleCursorAdapter(this,
R.layout.single_job_activity, cursor, fromColumns, toViews, 0);
listView = (ListView)findViewById(R.id.activities_list);
listView.setAdapter(cursoradapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.recent_job_list, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void addItemsOnSpinner(){
spinner = (Spinner) findViewById(R.id.time_periods_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.time_periods_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String s = parent.getItemAtPosition(position).toString();
//even the log doesn't show.
if(s.equals("Today")){
Log.d("today","today");
cursor = jobDatabaseHelper.getTodayJobs();
cursoradapter.notifyDataSetChanged();
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
Thank you!!!
Try using CursorAdapter.swapCursor(). That should work.
I am writing a note taking app within android eclipse. My app currently selects all the notes from within the SQLite database and uses them to populate a ListView. This ListView is clickable, and currently redirects the user to the EditNote activity.
However, I would like to be able to populate the EditTexts within the EditNote activity based on the ID of the ListView note that is clicked.
(So that if I clicked the first ListView Item and it's ID was 2 then the value 2 would be passed through to EditNote)
This would require obtaining the ID of the ListView Item that was clicked, and then passing it through using .putExtra(); to the EditNote activity.
So my question is: how would I obtain the ID and then pass it through to the EditNote activity? So that I can then use the ID to make additional querys on that activity.
Thank you very much for your time.
Any additional questions I will answer to the best of my ability.
Initialising things
DatabaseHelper dbh;
ArrayList<String> listItems = new ArrayList<String>();
ArrayAdapter<String> adapter;
Context mCtx;
ListView lv;
onCreate method with onClickListeners
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
refreshData();
mCtx = this;
lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
Intent i = new Intent(mCtx, EditNote.class);
i.putExtra("ID", listItems.get(position));
startActivity(i);
}
});
refreshData method (used to populate the ListView)
public void refreshData(){
dbh = new DatabaseHelper(this);
dbh.open();
adapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, listItems);
setListAdapter(adapter);
ArrayList<String[]> searchResult = new ArrayList<String[]>();
//EditText searchTitle = (EditText) findViewById(R.id.searchC);
listItems.clear();
searchResult = dbh.fetchNotes("");
//searchResult = dbh.fetchNotes(searchTitle.getText().toString());
String title = "", note = "", id = "";
for (int count = 0 ; count < searchResult.size() ; count++) {
note = searchResult.get(count)[2];
title = searchResult.get(count)[1];
id = searchResult.get(count)[0];
listItems.add(title);
}
adapter.notifyDataSetChanged();
}
/*private void setID(String setID) {
this.id = setID;
}
private String getID(){
return id;
}*/
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
DatabaseHelper activity - fetchNotes - used to query the database
public ArrayList<String[]> fetchNotes(String title) throws SQLException {
ArrayList<String[]> myArray = new ArrayList<String[]>();
int pointer = 0;
Cursor mCursor = mDb.query(TABLE_NAME, new String[] {"_id", "title",
"note"}, null, null,
null, null, "_id");
int idColumn = mCursor.getColumnIndex("_id");
int titleColumn = mCursor.getColumnIndex("title");
int noteColumn = mCursor.getColumnIndex("note");
if (mCursor != null){
//If possible move to the first record within the cursor
if (mCursor.moveToFirst()){
do {
//for each record add a new string array to our Array List
myArray.add(new String[3]);
//
myArray.get(pointer)[0] = mCursor.getString(idColumn);
//Save the note into the string array
myArray.get(pointer)[1] = mCursor.getString(titleColumn);
//Save the title into the string array
myArray.get(pointer)[2] = mCursor.getString(noteColumn);
//increment our pointer variable.
pointer++;
} while (mCursor.moveToNext()); // If possible move to the next record
} else {
myArray.add(new String[3]);
myArray.get(pointer)[0] = "";
myArray.get(pointer)[1] = "";
myArray.get(pointer)[2] = "";
}
}
return myArray;
}
Also here's my create table, just in case
private static final String DATABASE_CREATE =
"CREATE TABLE " + TABLE_NAME + " (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"title TEXT NOT NULL, " +
"note TEXT NOT NULL); ";
I will try to help you also i think your code can be more optimized ...
in your fetchNotes() just return the cursor instead of creating ArrayList if suppose you created ArrayList here and it occupies 100 entries again in the caller function you are using the listItems ArrayList... i know android has garbage collector but why to employ it if there is option to avoid ?
your myArray is String[] ArrayList but your listItems is not hence you can only access the titles coz this is wat you are storing here listItems.add(title);
a. So you can either use listItems directly in fetchNotes() like MainActivity.listitems (supposing listItem is declared in MainActivity class ) use after declaring ArrayList<String[]> listItems=new ArrayList<String[]>(); as public static ArrayList<String[]> listItems=new ArrayList<String[]>();
or
b. you can simply return the cursor only and do exactly like the myArray type of operation on listItems.
Now you can access the "id" by refering the index you stored the id in listItems.
listItems.get(position)[2] ( supposing you stored the id at index 2 ).
I tried to keep it as simple as possible and expect that it will help you ...
Not sure I understand this completely. Are you not passing the "title" already and your database helper can fetch results using "title"? Is this not working or do you want to optimize it by passing the ID? Even if you want to pass the ID, you can do that using the same mechanism.
I'm using predefined listview layout to show all the native messaging sms into my application.Code i defined in onCreate method:
lvInb = (ListView) findViewById(R.id.lvInb);
lvInb.setOnCreateContextMenuListener(this);
data = fetchInbox();
if(data!=null)
{
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1 , data);
lvInb.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lvInb.setAdapter(adapter);
}
for fetchInbox() I've created another method:
public ArrayList<String> fetchInbox()
{
ArrayList<String> sms = new ArrayList<String>();
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor cr = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null);
cr.moveToFirst();
while (cr.moveToNext())
{
sms.add(cr.getString(1)+"\n"+cr.getString(3)+"\n");
}
cr.close();
return sms;
}
code to delete row item in listview is:
private void openDelete() {
removeListViewItem();
}
public void removeListViewItem() {
if(intListViewItemPosition != -1){
lvInb.removeViewAt(intListViewItemPosition);
adapter.notifyDataSetInvalidated();
intListViewItemPosition = -1;
}else{
Toast.makeText(this, "No item selected", Toast.LENGTH_SHORT).show();
}
}
code in activity:
ListView lvInb;
ArrayAdapter<String> adapter;
int intListViewItemPosition = -1;
ArrayList<String> data;
Outside onCreate method:
#Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, view, menuInfo);
CreateMenu (menu);
}
#Override
public boolean onContextItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
MenuChoice(item);
return true;
}
private void CreateMenu(Menu menu)
{
MenuItem mnu1 = menu.add(0,0,0,"Delete");
{
mnu1.setIcon(R.drawable.ic_launcher);
}}
private boolean MenuChoice(MenuItem item)
{
switch (item.getItemId()) {
case 0:
removeListViewItem();
break;
}
return false;
}
public void removeListViewItem() {
intListViewItemPosition = lvInb.getSelectedItemPosition();
if(intListViewItemPosition != -1){
//lvInb.removeViewAt(intListViewItemPosition);
data.remove(intListViewItemPosition);
adapter.notifyDataSetInvalidated();
intListViewItemPosition = -1;
}else{
Toast.makeText(this, "No item selected", Toast.LENGTH_SHORT).show();
}
}
delete option i've provided in menu options. but when i select a row item and click on delete option it shows No item selected
Hey in where you are assigning the selected Item position value into "intListViewItemPosition"
If not used please implement this in your listview OnItemClickListener,
intListViewItemPosition= listView.getSelectedItemPosition();
You are trying to remove the selected Item from the listview right ?? for that you have clicked your listview item from the lisview, so you need to implement onClickListener for your listview
your code should be like this,
your_listView_name.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
intListViewItemPosition= listView.getSelectedItemPosition();
}
});
thats it..
first thing call fetchIndex only once:
declare an ArrayList of string in activity:
ArrayList<String> data;
ArrayAdapter<String> adapter
and in onCreate:
lvInb = (ListView) findViewById(R.id.lvInb);
lvInb.setOnCreateContextMenuListener(this);
data= fetchInbox();
if(data!=null)
{
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1 , data);
lvInb.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lvInb.setAdapter(adapter);
}
now change change removeListViewItem to:
public void removeListViewItem() {
intListViewItemPosition= lvInb.getSelectedItemPosition();
if(intListViewItemPosition != -1){
//lvInb.removeViewAt(intListViewItemPosition);
data.remove(intListViewItemPosition);
adapter.notifyDataSetInvalidated();
intListViewItemPosition = -1;
}else{
Toast.makeText(this, "No item selected", Toast.LENGTH_SHORT).show();
}
}
also have class level variable for adapter so that you can access it in removeListViewItem.
ArrayAdapter<String> adapter;
and in onCreate just say:
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1 , data);
If you declare it again in onCreate the class level one would be null and you might get null pointer when your removeListViewItem will get called.
I have a tab host activity using two separate databases. Each tab has a list view. I am trying to use a context menu to delete a list item with a long click. What I have will work on list1 tab, but will not delete the list item in the list2 tab. Here is my code:
public class TabListActivity extends TabActivity implementsOnTabChangeListener,OnClickListener{
private static final String LIST1_TAB_TAG = "Mixed Recipes";
private static final String LIST2_TAB_TAG = "Pre-Mixed Recipes";
// The two views in our tabbed example
private ListView listView1;
private ListView listView2;
private TabHost tabHost;
private DatabaseManager mDbHelper;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
mDbHelper = new DatabaseManager(this);
mDbHelper.open();
tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
// setup list view 1
listView1 = (ListView) findViewById(R.id.list1);
registerForContextMenu(listView1);
// setup list view 2
listView2 = (ListView) findViewById(R.id.list2);
registerForContextMenu(listView2);
// add views to tab host
tabHost.addTab(tabHost.newTabSpec(LIST1_TAB_TAG).setIndicator(LIST1_TAB_TAG).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listView1;
}
}));
tabHost.addTab(tabHost.newTabSpec(LIST2_TAB_TAG).setIndicator(LIST2_TAB_TAG).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listView2;
}
}));
tabHost.setCurrentTab(1);
tabHost.setCurrentTab(0);
}
/**
* Implement logic here when a tab is selected
*/
public void onTabChanged(String tabName) {
if(tabName.equals(LIST2_TAB_TAG)) {
//do something
fillDatapremix();
}
else if(tabName.equals(LIST1_TAB_TAG)) {
//do something
fillData();
}
}
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{DatabaseManager.KEY_NAME, DatabaseManager.KEY_ROWID};
//String1[] from = new String[]{DatabaseManager.KEY_ROWID};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{android.R.id.text1};
//int[] to = new int[]{android.R.id.text2};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2, notesCursor, from, to);
listView1.setAdapter(notes);
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent myIntent = new Intent(view.getContext(),
NoCalc.class);
myIntent.putExtra(DatabaseManager.KEY_ROWID, id);
startActivity(myIntent);
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
private void fillDatapremix() {
Cursor notesCursor = mDbHelper.fetchAllNotespremix();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{DatabaseManager.KEY_NAME, DatabaseManager.KEY_ROWID};
//String1[] from = new String[]{DatabaseManager.KEY_ROWID};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{android.R.id.text1};
//int[] to = new int[]{android.R.id.text2};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2, notesCursor, from, to);
listView2.setAdapter(notes);
listView2.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent myIntent = new Intent(view.getContext(),
Premix2.class);
myIntent.putExtra(DatabaseManager.KEY_ROWID, id);
startActivity(myIntent);
}
});
}
#Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
switch (v.getId()) {
}
menu.setHeaderTitle("Delete Recipe?");
menu.add(0, v.getId(), 0, "Delete");
}
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.list1:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper.deleteRow(info.id);
fillData();
return true;
case R.id.list2:
AdapterContextMenuInfo info1 = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper.deleteRow(info1.id);
fillData();
return true;
}
return false;
}
}
My question is, how do I get the second tab to delete the list item from the list and the database?
You have separate fillData() and fillDatapremix() functions and 2 separate functions to retrieve cursors from your 2 databases, but it looks like in your onContextItemSelected function you are using the same DatabaseManger delete function and fillData() function for each list.
Looks like you need to use a different delete function for your second database and then use fillDatapremix() to update the listView rather than fillData().