问题
PROBLEM
I want to click Listview Programmatically after onResume() and retain ListView but I don't know when and where should I implement click logic because now it Force close because I call function to early (I have check return view is null)
I use Handler() Runnable() and Thread() method becuase I think that this will queue my code after listview finish implementation.
What should I do??
EXAMPLE OF USING HANDLER RUNNABLE and THREAD
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
DataManager dm = new DataManager(getActivity());
for (int i = 0; i < scheduleLvItems.size(); i++) {
if (dm.readPF(String.valueOf(i)).equals("open")) {
System.out.println("RESTATE -----------------> " + i);
if(isAdded())
System.out.println("TOGGLE POSITION ----> "+ i);
toggle(i, false, 0);
}
}
}
});
}
};
new Thread(runnable).start();
LOGCAT
6-10 15:19:24.349 314-314/com.bis.org.auInsight E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.bis.org.auInsight.ScreenSlidePageFragment.toggleAnimation(ScreenSlidePageFragment.java:517)
at com.bis.org.auInsight.ScreenSlidePageFragment.toggle(ScreenSlidePageFragment.java:487)
at com.bis.org.auInsight.ScreenSlidePageFragment.access$100(ScreenSlidePageFragment.java:24)
at com.bis.org.auInsight.ScreenSlidePageFragment$1$1.run(ScreenSlidePageFragment.java:117)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
On line 517
listItem.getWrapper().startAnimation(resizeAnimation);
DEBUG CODE
System.out.println("DEBUG GET WRAPPER -> "+schedule_listView.getWrapper());
DEBUG RESULT
06-10 15:19:24.329 314-314/com.bis.org.auInsight I/System.out﹕ DEBUG GET WRAPPER -> null
回答1:
Your question isn't clear. Please edit it to state exactly what you're asking and provide all details concisely.
The exception you're receiving is caused by the fact that getWrapper()
returns null
. What is this function? Did you implement it yourself? Try to debug inside and see why it's null
.
Also, I see no point in wrapping a Runnable
in another Runnable
. Why not post the inner Runnable
directly?
Maybe the code in the separate thread doesn't run before you call getWrapper()
and that's why it returns null
?
来源:https://stackoverflow.com/questions/24136375/android-check-when-listview-finish-implementation-or-ready