Android : check when listview finish implementation or ready

ⅰ亾dé卋堺 提交于 2019-12-12 02:48:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!