Excuse me. I am weak in English Language. Please do not negative score! I know how to search the list view of the dynamic view ... But I do not know how to search the database list view . Can you tell me search codes list view the values of its items database is filled ?
this is my codes in database class:
public DrLists findProduct(String Title) {
String query = "Select * FROM " + TABLE_NAME + " WHERE " + TABLE_NAME + " = \"" + Title + "\"" ;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
drLists=new DrLists();
if (cursor.moveToFirst()) {
cursor.moveToFirst();
drLists.setId(Integer.parseInt(cursor.getString(0)));
drLists.setName(cursor.getString(1));
drLists.setFamily(cursor.getString(2));
cursor.close();
} else {
drLists = null;
}
db.close();
return drLists;
}
and this is my codes in Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation);
databaseAssets=new DatabaseAssets(getApplicationContext());
try {
databaseAssets.createDataBase();
databaseAssets.openDataBase();
}catch (IOException e){
e.printStackTrace();
}
editText=(EditText)findViewById(R.id.edt_search);
Button search = (Button)findViewById(R.id.btn_search);
drawerLayout = (DrawerLayout) findViewById(R.id.my_drawerlayout);
navigationView = (NavigationView) findViewById(R.id.my_navigation);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.setDrawerListener(toggle);
toggle.syncState();
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drLists=new DrLists();
drLists=databaseAssets.findProduct(editText.getText().toString());
}
});
But does not findProduct function! What is the problem?
Aucun commentaire:
Enregistrer un commentaire