I am not familiar with databases I have a database file named words_library.db
that contains a table named dictionary_lib
in which there is two columns one is English_lib
and the second is German_lib
what I want to achieve is:
When the user types a word in the search box and validates a dialog box appears showing results like the following picture (check fig. 1) here's the code I have so far:
Java
db =new DataBaseHelper(getContext());
try {
db.createDataBase();
db.openDataBase();
}
catch (Exception e)
{
e.printStackTrace();
}
namelist=new LinkedHashMap<>();
int ii;
SQLiteDatabase sd = db.getReadableDatabase();
Cursor cursor = sd.query("dictionary_lib" ,null, null, null, null, null, null);
ii=cursor.getColumnIndex("English_lib");
eng_list=new ArrayList<String>();
german_list= new ArrayList<String>();
while (cursor.moveToNext()){
namelist.put(cursor.getString(ii), cursor.getString(cursor.getColumnIndex("German_lib")));
}
Iterator entries = namelist.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry thisEntry = (Map.Entry) entries.next();
eng_list.add(String.valueOf(thisEntry.getKey()));
german_list.add(String.valueOf(thisEntry.getValue()));
}
for (int i = 0; i < eng_list.size(); i++){
if (eng_list.contains(text)){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
builder.setTitle(text);
builder.setMessage(
"\n'word' in german: "+german_list.get(i).toString()
);
builder.setNegativeButton("CLOSE", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
Stxt.setBackground(getResources().getDrawable(R.drawable.blue_out_line));
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
Desired result (fig. 1)