android - Get user input from EditText, query that word from SQLite database and populate result -


i learning programming , trying developing basic dictionary application using android studio.

database , table created, when application runs , able populate data using following query. cursor res = db.rawquery("select * " + table_name + " word = 'home' ", null);

the problems that, in mainactivity class, have created method

public edittext getedittext(){     edittext gettext = (edittext)findviewbyid(r.id.edittext_searchwords);     return gettext; } 

and in databasehelper class.

public cursor getword() {     mainactivity obj = new mainactivity();     edittext searchword = obj.getedittext();     string word = searchword.gettext().tostring();      sqlitedatabase db = this.getwritabledatabase();     cursor res = db.rawquery("select * " + table_name + " word ="+word, null);     return res; } 

however, after implementing above query , method, app crashes , not anything. have been playing week , couldn't figure out problems. great support in learning.

you cant create new main activity object , pull view it. if you're calling getword() inside activity try passing in text parameter instead since have access edittext there.

and if call method activity , fix that, shouldn't access db live thread.

look using cursorloader: http://developer.android.com/training/load-data-background/setup-loader.html

or calling asyctask runs query , returns response:

http://developer.android.com/reference/android/os/asynctask.html


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -