java - Android setOnClickListener does not work -
i've little problem toast in android :/ want create little toast when button1
going activated
here code:
mainactivity.java
package com.andruiden.toast; import android.app.activity; import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener; import android.os.bundle; import android.view.*; import android.widget.*; import com.andruiden.toast.r; public class mainactivity extends activity { //klick listener class meinclicklistener implements onclicklistener{ public void onclick(view v){ string text = "es wurde geklickt"; toast t = toast.maketext(v.getcontext(), text, toast.length_short); t.show(); } @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub } } public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //button beim hörer registrieren meinclicklistener t = new meinclicklistener(); button test = (button) findviewbyid(r.id.button1); test.setonclicklistener(t); } }
on line test.setonclicklistener(t);
error:
the method setonclicklistener(view.onclicklistener) in type view not applicable arguments
what means?
i can change code here:
test.setonclicklistener((android.view.view.onclicklistener) t);
but when run .apk on galaxy s2 happens nothing.. :/
sorry bad english xd
please remove these lines import section:
import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener;
these dialog interfaces
and use instead:
import android.view.view.onclicklistener;
your class should be:
class meinclicklistener implements onclicklistener { public void onclick(view v) { string text = "es wurde geklickt"; toast t = toast.maketext(v.getcontext(), text, toast.length_short); t.show(); } }
Comments
Post a Comment