android - performItemClick not working after setAdapter -
[solved]
i have following structure in code:
listview accountlistview = (listview) findviewbyid(r.id.accountlisting); arrayadapter<string> adapter = new arrayadapter<string>(this, r.layout.list_view_item, r.id.nametextview, currentaccounts); accountlistview.setadapter(adapter); accountlistview.performitemclick(null, 0, 0);
currentaccounts array, , has data on it.
when try performitemclick after setting adapter, nullpointerexception.
i override onkeypress, run "performitemclick" , works fine.
i know why doesn't work when trying perform click after setting adapter. (after debugging saw lastvisibleposition -1) why?
[edit]
using ((listview)findviewbyid(r.id.accountlisting)).performitemclick(null, 0, 0);
works, except, if used right after setting adapter. (look @ comments more info)
[edit 2]
stack trace:
07-24 13:07:56.710: e/androidruntime(9455): fatal exception: main 07-24 13:07:56.710: e/androidruntime(9455): java.lang.runtimeexception: unable start activity componentinfo{com.app.device/com.app.device.welcomeactivity}: java.lang.nullpointerexception 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activitythread.performlaunchactivity(activitythread.java:2097) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2122) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activitythread.access$600(activitythread.java:140) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activitythread$h.handlemessage(activitythread.java:1228) 07-24 13:07:56.710: e/androidruntime(9455): @ android.os.handler.dispatchmessage(handler.java:99) 07-24 13:07:56.710: e/androidruntime(9455): @ android.os.looper.loop(looper.java:137) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activitythread.main(activitythread.java:4895) 07-24 13:07:56.710: e/androidruntime(9455): @ java.lang.reflect.method.invokenative(native method) 07-24 13:07:56.710: e/androidruntime(9455): @ java.lang.reflect.method.invoke(method.java:511) 07-24 13:07:56.710: e/androidruntime(9455): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:994) 07-24 13:07:56.710: e/androidruntime(9455): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:761) 07-24 13:07:56.710: e/androidruntime(9455): @ dalvik.system.nativestart.main(native method) 07-24 13:07:56.710: e/androidruntime(9455): caused by: java.lang.nullpointerexception 07-24 13:07:56.710: e/androidruntime(9455): @ com.app.device.welcomeactivity.unselectviews(welcomeactivity.java:1637) 07-24 13:07:56.710: e/androidruntime(9455): @ com.app.device.welcomeactivity.access$24(welcomeactivity.java:1632) 07-24 13:07:56.710: e/androidruntime(9455): @ com.app.device.welcomeactivity$27.onitemclick(welcomeactivity.java:1447) 07-24 13:07:56.710: e/androidruntime(9455): @ android.widget.adapterview.performitemclick(adapterview.java:298) 07-24 13:07:56.710: e/androidruntime(9455): @ android.widget.abslistview.performitemclick(abslistview.java:1280) 07-24 13:07:56.710: e/androidruntime(9455): @ com.app.device.welcomeactivity.updateaccountlist(welcomeactivity.java:1653) 07-24 13:07:56.710: e/androidruntime(9455): @ com.app.device.welcomeactivity.oncreate(welcomeactivity.java:238) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activity.performcreate(activity.java:5163) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1094) 07-24 13:07:56.710: e/androidruntime(9455): @ android.app.activitythread.performlaunchactivity(activitythread.java:2061) 07-24 13:07:56.710: e/androidruntime(9455): ... 11 more
thanks in advance!
[solution]
i trying performitemclick on oncreate()
method, screen not visible user. using onwindowfocuschanged()
worked! onwindowfocuschanged() on android documentation.
thanks everybody.
you passing null parameter perfomitemclick, have tried:
listview accountlistview = (listview) findviewbyid(r.id.accountlisting); arrayadapter<string> adapter = new arrayadapter<string>(this, r.layout.list_view_item, r.id.nametextview, currentaccounts); accountlistview.setadapter(adapter); accountlistview.performitemclick(adapter, 0, 0);
hope helps...
regards!
Comments
Post a Comment