android - SimpleCursorAdapter not returning position -
i searched stackoverflow similar questions. none of solutions seem work.
this customadapter class.
public class contactadapter extends simplecursoradapter { context cont; public contactadapter(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to, 0); cont = context; } @override public view getview(final int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); button button = (button)view.findviewbyid(r.id.delete_button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(cont, position, toast.length_short).show(); } }); return view; } }
as per docs should position of current item in toast. throws following exceptions.
08-13 13:46:01.904: e/androidruntime(5980): android.content.res.resources$notfoundexception: string resource id #0x0 08-13 13:46:01.904: e/androidruntime(5980): @ android.content.res.resources.gettext(resources.java:265) 08-13 13:46:01.904: e/androidruntime(5980): @ android.widget.toast.maketext(toast.java:265) 08-13 13:46:01.904: e/androidruntime(5980): @ com.example.databaseproject.contactadapter$1.onclick(contactadapter.java:34) 08-13 13:46:01.904: e/androidruntime(5980): @ android.view.view.performclick(view.java:4091) 08-13 13:46:01.904: e/androidruntime(5980): @ android.view.view$performclick.run(view.java:17072) 08-13 13:46:01.904: e/androidruntime(5980): @ android.os.handler.handlecallback(handler.java:615) 08-13 13:46:01.904: e/androidruntime(5980): @ android.os.handler.dispatchmessage(handler.java:92) 08-13 13:46:01.904: e/androidruntime(5980): @ android.os.looper.loop(looper.java:153) 08-13 13:46:01.904: e/androidruntime(5980): @ android.app.activitythread.main(activitythread.java:5034) 08-13 13:46:01.904: e/androidruntime(5980): @ java.lang.reflect.method.invokenative(native method) 08-13 13:46:01.904: e/androidruntime(5980): @ java.lang.reflect.method.invoke(method.java:511) 08-13 13:46:01.904: e/androidruntime(5980): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:821) 08-13 13:46:01.904: e/androidruntime(5980): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:584) 08-13 13:46:01.904: e/androidruntime(5980): @ dalvik.system.nativestart.main(native method)
please help.
the problem position
int , toast.maketext
method's second parameter( if int) must resource id. here, there no resource id position
, resources$notfoundexception
how fix it?
just cast string position + ""
use code
button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(cont, position+"", toast.length_short).show(); } });
Comments
Post a Comment