mercredi 4 novembre 2015

SQLIte not displaying all of the results correctly in ListView

I am having trouble with displaying the results in the search activity of my app. I wonder where it went wrong.

The aim of the function below is to search the input query of the user and find it in every files listed. But the results only matches one data eventhough the query is also present in the other files. Here is the code.

 public void searchFiles(File[] filelist, String query, String querysearch, String[] namesOfFiles){
    querysearch = "SELECT * FROM (SELECT * FROM Data WHERE ObjectID = ? ORDER BY _id DESC LIMIT 10) sub ORDER BY _id DESC";
    int temp2 = filelist.length;
    for (int i = (temp2-1); i >= 0; i--) {
        if(!(filelist[i].getName().equals("DataObjectDB.db")) && !(filelist[i].getName().endsWith("-journal"))){
            temp1 = filelist[i].getName();
            namesOfFiles[i] = temp1.replaceAll(".db$", "");
            Toast.makeText(getApplicationContext(),"Searching " + query + " in: " + namesOfFiles[i], Toast.LENGTH_SHORT).show();
            DatabaseHelper db1 = new DatabaseHelper(getApplicationContext(),namesOfFiles[i]);
            SQLiteDatabase sqldb = db1.getWritableDatabase();
            cursor = sqldb.rawQuery(querysearch, new String[]{query});
            Toast.makeText(getApplicationContext(),cursor.toString(), Toast.LENGTH_SHORT).show();
        }
    }
    final ListView listView = (ListView) findViewById(R.id.results_listview);
    SearchAdapter adapter = new SearchAdapter(this, R.layout.results_column, cursor,0 );
    listView.setAdapter(adapter);
}

The searchFiles() function passes the filelist, query, querysearch and namesOfFiles where 1) filelist contains the list of files in the source folder 2) query is the user input he/she wants to search 3) querysearch is the select statement 3) namesofFiles is just an empty string.

I indicate a toast to see if the code traverses through all the folders. And yes it is. But I don't know why it is not displaying all the results.

Any help? Thanks!

Aucun commentaire:

Enregistrer un commentaire