android自定义列表视图位置和点击事件问题(列表从服务器获取动态数据)

时间:2012-02-29 05:59:03

标签: android

我需要更多的帮助。实际上我面临的一个问题是我的列表视图在每3秒后获取新数据,因为我问你现在工作正常。但是当我点击listrow时出现问题(启动新活动显示visitordetail页面)我将一些数据从listview行传递到另一个activity.my问题是listview在每3秒后获取新数据,当我点击listrow然后下一个活动开始并在案例更新中显示visitordetail页面在单击列表视图行之前调用方法但是如果我单击该行并且同时接收到新数据并将其添加到应用程序崩溃的行中。

如果我的应用程序没有崩溃并且点击行或行的button.i时,我应该怎么做才能将与该行相关的sessiontext和iptext传递给下一个活动。

我的班级代码遵循以下链接。 http://www.coderanch.com/t/568877/Android/Mobile/android-custom-list-view-position#2585198 eranch.com/t/568803/Android/Mobile/start-new-activity-when-click

当我点击listiview行更新列表方法停止并且新活动开始时我更喜欢我的应用程序,当我从新活动回来时,再次启动更新方法,这怎么可能?

当我回到下一个活动时,我的logcat就像以下.............

02-29 12:53:53.463: E/AndroidRuntime(5066): FATAL EXCEPTION: main
02-29 12:53:53.463: E/AndroidRuntime(5066): java.lang.RuntimeException: Unable to resume activity {com.live2support/com.live2support.L2STest}: java.lang.IllegalStateException: Timer was cancelled
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2059)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.os.Looper.loop(Looper.java:123)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at java.lang.reflect.Method.invokeNative(Native Method)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at java.lang.reflect.Method.invoke(Method.java:521)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at dalvik.system.NativeStart.main(Native Method)
02-29 12:53:53.463: E/AndroidRuntime(5066): Caused by: java.lang.IllegalStateException: Timer was cancelled
02-29 12:53:53.463: E/AndroidRuntime(5066):     at java.util.Timer.scheduleImpl(Timer.java:566)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at java.util.Timer.schedule(Timer.java:485)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at com.live2support.BaseActivity.onStart(BaseActivity.java:157)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at com.live2support.BaseActivity.onRestart(BaseActivity.java:932)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.Instrumentation.callActivityOnRestart(Instrumentation.java:1139)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.Activity.performRestart(Activity.java:3805)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityThread.performRestartActivity(ActivityThread.java:3477)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:160)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:518)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.Activity.performResume(Activity.java:3823)
02-29 12:53:53.463: E/AndroidRuntime(5066):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)

当我点击listrow应用程序崩溃时,在这种情况下,新的数据更新调用已启动,我清除了我的事件的计时器和代码,就像这一次崩溃我的应用程序.........

convertView.setOnClickListener(new OnClickListener(){

                    public void onClick(View v) {
                        timer.purge();
                        if(SessionText.get(position)!=null&&IPText.get(position)!=null){
                        Intent i=new Intent(BaseActivity.this,VisitorDetail.class);
                        i.putExtra("ID", id);
                        i.putExtra("Position",position);
                        i.putExtra("From", from);
                        i.putExtra("SessionText", SessionText.get(position));
                        i.putExtra("IPTEXT",IPText.get(position));
                        startActivity(i);

                        }

                        else{

                            timer.schedule(new TimerTask() {
                                public void run() {
                                    TimerMethod();
                                }

                            }, 0, 3000); 
                        }



                    }});

任何人都可以帮我解决问题.....................

2 个答案:

答案 0 :(得分:1)

取消计时器onItemClick,因此当您点击某个项目时它不会更新数据,如果在单击项目后需要它,则在调用startActivity后再次启动计时器。

答案 1 :(得分:0)

使用java synchronized块