Saturday 15 January 2011

android - I want to set textfield from separate class -



android - I want to set textfield from separate class -

when utilize setui() in onupgrade in sqliteopenhelper, nullpointerexception displayed. why this? want display textfield on display separate class, if there other way, please tell me that. (for illustration layoutinflater? but, when used layoutinflater, showed nothing.)

public class myactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my);        ・        ・        ・ public void setui(string filename,string word,string yen,string category){ textview categorytext=(textview)findviewbyid(r.id.category); categorytext.settext(category); bitmap image=loadimage(filename,this); imageview imageview=(imageview)findviewbyid(r.id.image); imageview.setimagebitmap(image); textview wordtext=(textview)findviewbyid(r.id.word); wordtext.settext(word); textview yentext=(textview)findviewbyid(r.id.yen); yentext.settext(yen); } private static class dbhelper extends sqliteopenhelper { public dbhelper(context context) { super(context,db_name,null,4); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table if not exists "+db_table+"(id integer primary key autoincrement,image text,word text, yen text)"); } @override public void onupgrade(sqlitedatabase db, int oldversion,int newversion) { db.execsql("create table if not exists "+category_db_table+"(id integer primary key autoincrement, category text)"); db.execsql("insert category(category) values('カテゴリー1')"); cursor c=db.rawquery("select * test inner bring together category on test.id = category.id",null); c.movetofirst(); myactivity myactivity=new myactivity(); myactivity.setui(c.getstring(1),c.getstring(2),c.getstring(3),c.getstring(5)); }

you calling myactivity.setui after instanting myactivity class. time view not have been inflated.

instead should seek store required info in myactivity in variable , check presence in oncreate method after setcontentview phone call , phone call setui method. called if activity displayed on screen.

android

No comments:

Post a Comment