java - Toast call inside of a button tap giving an error that i can't figure out -


i trying make toast display information stored in text variable when submitbtn clicked. error getting not in running of code eclipse telling me :

the method maketext(context, charsequence, int) in type toast not applicable arguments (class, string, int)

the file toast in userinput.java file. here current code block:

button submitbtn = (button) findviewbyid(r.id.buttonsubmit);     submitbtn.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             int position = spinner.getselecteditemposition();             string text = null;              text = dayarray[position].tostring();             //log.i("spinner test: ", text);             toast toast = toast.maketext(userinput.class, text, toast.length_long).show();         }     }); 

i have tried set context userinput.this , getapplicationcontext() , gives me error:

type mismatch: cannot convert void toast

i let know android novice , of java novice have searched high , low , can not find solutions work. toast not important app developing , taken out want know why not work learning process.

change

toast toast = toast.maketext(userinput.class, text, toast.length_long).show(); 

to

toast.maketext(userinput.this, text, toast.length_long).show(); 

you need use activity context use activityname.this.

but original problem if doing way need call statically because calling show().

you take off show() , create instance of toast if wanted other things such call setview() use custom view toast. call show() on toast instance created.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -