I've been looking up for any answers in various site but none of them answers to my problem. I'm trying to use the fts to do a search from my single database that contains multiple tables that then needs to be displayed into the recyclerview. I'm trying to use the Search Dialog by the way. I read the official android docs as well as it's sample Search Dictionary but I've noticed that it fetches it's data( the list of definitions) from a raw file named definition.txt which is confusing for me since it happens that I need to fetch mine from my SQLite database also I'm using recyclerview as well. Below is a sample image from my table C++ which displays the list of terms fetched from my SQLite Database and there is a search filter here as well(this search is different from what I'm asking since it is only specific to it's table while the search in question is a general one meaning that it performs search that includes all table).
Following image is from my home that has search view(I haven't done any functionality yet.)
That is where I need to apply my questions. I'm actually am confuse on how to implement it right now especially the part where it has suggestions when typing like an autocomplete and then displaying results in recyclerview.
Below is my database
public class LangDatabaseHelper extends SQLiteOpenHelper {
//database name
public static final String DBASE = "Language";
//tables
public static final String TBLCPP = "cpp";
public static final String TBLHTML = "html";
public static final String TBLJAVA = "java";
public static final String TBLJS = "js";
public static final String TBLPHP = "php";
public static final String TBLSQL = "sql";
public static final String TBLXML = "xml";
//db version
public static final int DBVERSION = 1;
//fields
public static final String C_TERM = "c_terms";
public static final String C_ID = "c_id";
public static final String C_DEF = "c_def";
public static final String C_SYNTAX = "c_syntax";
public static final String C_CODE = "c_code";
public static final String HTML_TERM = "html_terms";
public static final String HTML_ID = "html_id";
public static final String HTML_DEF = "html_def";
public static final String HTML_SYNTAX = "html_syntax";
public static final String HTML_CODE = "html_code";
public static final String JAVA_TERM = "java_terms";
public static final String JAVA_ID = "java_id";
public static final String JAVA_DEF = "java_def";
public static final String JAVA_SYNTAX = "java_syntax";
public static final String JAVA_CODE = "java_code";
public static final String JS_TERM = "js_terms";
public static final String JS_ID = "js_id";
public static final String JS_DEF = "js_def";
public static final String JS_SYNTAX = "js_syntax";
public static final String JS_CODE = "js_code";
public static final String PHP_TERM = "php_terms";
public static final String PHP_ID = "php_id";
public static final String PHP_DEF = "php_def";
public static final String PHP_SYNTAX = "php_syntax";
public static final String PHP_CODE = "php_code";
public static final String SQL_TERM = "sql_terms";
public static final String SQL_ID = "sql_id";
public static final String SQL_DEF = "sql_def";
public static final String SQL_SYNTAX = "sql_syntax";
public static final String SQL_CODE = "sql_code";
public static final String XML_TERM = "xml_terms";
public static final String XML_ID = "xml_id";
public static final String XML_DEF = "xml_def";
public static final String XML_SYNTAX = "xml_syntax";
public static final String XML_CODE = "xml_code";
public LangDatabaseHelper(Context context) {
super(context, DBASE, null, DBVERSION);
// TODO Auto-generated constructor stub
SQLiteDatabase db = this.getWritableDatabase();
Log.d("Database operation","Database created...");
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE "+TBLCPP+" ("+ C_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+C_TERM+" TEXT, "+C_DEF+" TEXT, "+C_SYNTAX+" TEXT, "+C_CODE+" TEXT )");
Log.d("Database operation", "Table C++ created...");
db.execSQL("CREATE TABLE "+TBLHTML+" ("+ HTML_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+HTML_TERM+" TEXT, "+HTML_DEF+" TEXT, "+HTML_SYNTAX+" TEXT, "+HTML_CODE+" TEXT )");
Log.d("Database operation", "Table HTML created...");
db.execSQL("CREATE TABLE "+TBLJAVA+" ("+ JAVA_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+JAVA_TERM+" TEXT, "+JAVA_DEF+" TEXT, "+JAVA_SYNTAX+" TEXT, "+JAVA_CODE+" TEXT )");
Log.d("Database operation", "Table Java created...");
db.execSQL("CREATE TABLE "+TBLJS+" ("+ JS_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+JS_TERM+" TEXT, "+JS_DEF+" TEXT, "+JS_SYNTAX+" TEXT, "+JS_CODE+" TEXT )");
Log.d("Database operation", "Table JS created...");
db.execSQL("CREATE TABLE "+TBLPHP+" ("+ PHP_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+PHP_TERM+" TEXT, "+PHP_DEF+" TEXT, "+PHP_SYNTAX+" TEXT, "+PHP_CODE+" TEXT )");
Log.d("Database operation", "Table PHP created...");
db.execSQL("CREATE TABLE "+TBLSQL+" ("+ SQL_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+SQL_TERM+" TEXT, "+SQL_DEF+" TEXT, "+SQL_SYNTAX+" TEXT, "+SQL_CODE+" TEXT )");
Log.d("Database operation", "Table SQL created...");
db.execSQL("CREATE TABLE "+TBLXML+" ("+ XML_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+XML_TERM+" TEXT, "+XML_DEF+" TEXT, "+XML_SYNTAX+" TEXT, "+XML_CODE+" TEXT )");
Log.d("Database operation", "Table XML created...");
}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS "+TBLCPP);
Log.d("Database operation", "Database C++ updated...");
db.execSQL("DROP TABLE IF EXISTS "+TBLHTML);
Log.d("Database operation", "Database HTML updated...");
db.execSQL("DROP TABLE IF EXISTS "+TBLJAVA);
Log.d("Database operation", "Database Java updated...");
db.execSQL("DROP TABLE IF EXISTS "+TBLJS);
Log.d("Database operation", "Database JS updated...");
db.execSQL("DROP TABLE IF EXISTS "+TBLPHP);
Log.d("Database operation", "Database PHP updated...");
db.execSQL("DROP TABLE IF EXISTS "+TBLSQL);
Log.d("Database operation", "Database MySQL updated...");
db.execSQL("DROP TABLE IF EXISTS "+TBLXML);
Log.d("Database operation", "Database XML updated...");
onCreate(db);
}
/**
public void putAllJava(String term, String def, String syntax, String code, SQLiteDatabase db){
ContentValues cv = new ContentValues();
cv.put(JAVA_TERM, term);
cv.put(JAVA_DEF, def);
cv.put(JAVA_SYNTAX, syntax);
cv.put(JAVA_CODE, code);
long l = db.insert(TBLJAVA, null, cv);
Log.d("Database operation", "One row inserted...");
}
public Cursor getAllJava(SQLiteDatabase db){
String[] projection = {JAVA_TERM, JAVA_DEF, JAVA_SYNTAX, JAVA_CODE};
Cursor c = db.query(TBLJAVA, projection, null, null, null, null, null);
return c;
}
*/
//C++ CRUD
public void putAllCpp( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(C_TERM, datamodel.getTerm());
db_values.put(C_DEF, datamodel.getDefinition());
db_values.put(C_SYNTAX, datamodel.getSyntax());
db_values.put(C_CODE, datamodel.getCode());
db.insert(TBLCPP, null, db_values);
db.close();
}
public List<DataModel> getAllCppDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLCPP;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(C_ID);
int index1 = c.getColumnIndex(C_TERM);
int index2 = c.getColumnIndex(C_DEF);
int index3 = c.getColumnIndex(C_SYNTAX);
int index4 = c.getColumnIndex(C_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deleteCppTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLCPP);
db.execSQL("CREATE TABLE "+TBLCPP+" ("+ C_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+C_TERM+" TEXT, "+C_DEF+" TEXT, "+C_SYNTAX+" TEXT, "+C_CODE+" TEXT )");
Log.d("Updating Table C++", "Updating...");
db.close();
}
//HTML5 CRUD
public void putAllHtml( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(HTML_TERM, datamodel.getTerm());
db_values.put(HTML_DEF, datamodel.getDefinition());
db_values.put(HTML_SYNTAX, datamodel.getSyntax());
db_values.put(HTML_CODE, datamodel.getCode());
db.insert(TBLHTML, null, db_values);
db.close();
}
public List<DataModel> getAllHtmlDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLHTML;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(HTML_ID);
int index1 = c.getColumnIndex(HTML_TERM);
int index2 = c.getColumnIndex(HTML_DEF);
int index3 = c.getColumnIndex(HTML_SYNTAX);
int index4 = c.getColumnIndex(HTML_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deleteHtmlTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLHTML);
db.execSQL("CREATE TABLE "+TBLHTML+" ("+ HTML_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+HTML_TERM+" TEXT, "+HTML_DEF+" TEXT, "+HTML_SYNTAX+" TEXT, "+HTML_CODE+" TEXT )");
Log.d("Updating Table HTML", "Updating...");
db.close();
}
//JAVA CRUD
public void putAllJava( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(JAVA_TERM, datamodel.getTerm());
db_values.put(JAVA_DEF, datamodel.getDefinition());
db_values.put(JAVA_SYNTAX, datamodel.getSyntax());
db_values.put(JAVA_CODE, datamodel.getCode());
db.insert(TBLJAVA, null, db_values);
db.close();
}
public List<DataModel> getAllJavaDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLJAVA;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(JAVA_ID);
int index1 = c.getColumnIndex(JAVA_TERM);
int index2 = c.getColumnIndex(JAVA_DEF);
int index3 = c.getColumnIndex(JAVA_SYNTAX);
int index4 = c.getColumnIndex(JAVA_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deleteJavaTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLJAVA);
db.execSQL("CREATE TABLE "+TBLJAVA+" ("+ JAVA_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+JAVA_TERM+" TEXT, "+JAVA_DEF+" TEXT, "+JAVA_SYNTAX+" TEXT, "+JAVA_CODE+" TEXT )");
Log.d("Updating Table Java", "Updating...");
db.close();
}
//JS CRUD
public void putAllJs( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(JS_TERM, datamodel.getTerm());
db_values.put(JS_DEF, datamodel.getDefinition());
db_values.put(JS_SYNTAX, datamodel.getSyntax());
db_values.put(JS_CODE, datamodel.getCode());
db.insert(TBLJS, null, db_values);
db.close();
}
public List<DataModel> getAllJsDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLJS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(JS_ID);
int index1 = c.getColumnIndex(JS_TERM);
int index2 = c.getColumnIndex(JS_DEF);
int index3 = c.getColumnIndex(JS_SYNTAX);
int index4 = c.getColumnIndex(JS_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deleteJsTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLJS);
db.execSQL("CREATE TABLE "+TBLJS+" ("+ JS_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+JS_TERM+" TEXT, "+JS_DEF+" TEXT, "+JS_SYNTAX+" TEXT, "+JS_CODE+" TEXT )");
Log.d("Updating Table JS", "Updating...");
db.close();
}
//PHP CRUD
public void putAllPhp( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(PHP_TERM, datamodel.getTerm());
db_values.put(PHP_DEF, datamodel.getDefinition());
db_values.put(PHP_SYNTAX, datamodel.getSyntax());
db_values.put(PHP_CODE, datamodel.getCode());
db.insert(TBLPHP, null, db_values);
db.close();
}
public List<DataModel> getAllPhpDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLPHP;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(PHP_ID);
int index1 = c.getColumnIndex(PHP_TERM);
int index2 = c.getColumnIndex(PHP_DEF);
int index3 = c.getColumnIndex(PHP_SYNTAX);
int index4 = c.getColumnIndex(PHP_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deletePhpTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLPHP);
db.execSQL("CREATE TABLE "+TBLPHP+" ("+ PHP_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+PHP_TERM+" TEXT, "+PHP_DEF+" TEXT, "+PHP_SYNTAX+" TEXT, "+PHP_CODE+" TEXT )");
Log.d("Updating Table PHP", "Updating...");
db.close();
}
//SQL CRUD
public void putAllSql( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(SQL_TERM, datamodel.getTerm());
db_values.put(SQL_DEF, datamodel.getDefinition());
db_values.put(SQL_SYNTAX, datamodel.getSyntax());
db_values.put(SQL_CODE, datamodel.getCode());
db.insert(TBLSQL, null, db_values);
db.close();
}
public List<DataModel> getAllSqlDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLSQL;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(SQL_ID);
int index1 = c.getColumnIndex(SQL_TERM);
int index2 = c.getColumnIndex(SQL_DEF);
int index3 = c.getColumnIndex(SQL_SYNTAX);
int index4 = c.getColumnIndex(SQL_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deleteSqlTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLSQL);
db.execSQL("CREATE TABLE "+TBLSQL+" ("+ SQL_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+SQL_TERM+" TEXT, "+SQL_DEF+" TEXT, "+SQL_SYNTAX+" TEXT, "+SQL_CODE+" TEXT )");
Log.d("Updating Table SQL", "Updating...");
db.close();
}
//XML CRUD
public void putAllXml( DataModel datamodel ) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues db_values = new ContentValues();
db_values.put(XML_TERM, datamodel.getTerm());
db_values.put(XML_DEF, datamodel.getDefinition());
db_values.put(XML_SYNTAX, datamodel.getSyntax());
db_values.put(XML_CODE, datamodel.getCode());
db.insert(TBLXML, null, db_values);
db.close();
}
public List<DataModel> getAllXmlDataModel(){
List<DataModel> dataList = new ArrayList<DataModel>();
String query = "SELECT * FROM " + TBLXML;
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(query, null);
while(c.moveToNext()){
int index0 = c.getColumnIndex(XML_ID);
int index1 = c.getColumnIndex(XML_TERM);
int index2 = c.getColumnIndex(XML_DEF);
int index3 = c.getColumnIndex(XML_SYNTAX);
int index4 = c.getColumnIndex(XML_CODE);
int id = c.getInt(index0);
String term = c.getString(index1);
String def = c.getString(index2);
String syn = c.getString(index3);
String code = c.getString(index4);
DataModel model = new DataModel(id, term, def, syn, code);
dataList.add(model);
}
return dataList;
}
public void deleteXmlTable(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS "+TBLXML);
db.execSQL("CREATE TABLE "+TBLXML+" ("+ XML_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+XML_TERM+" TEXT, "+XML_DEF+" TEXT, "+XML_SYNTAX+" TEXT, "+XML_CODE+" TEXT )");
Log.d("Updating Table XML", "Updating...");
db.close();
}
}