当前位置:编程学习 > wap >>

ListView 刷新的问题 请大哥们指点下

还是在为某单位开发一个管理系统,里面用到ListView来显示XML文件中的数据。因为有好几个XML文件要显示,所以页面中设置了几个radiobutton分别对应不同的XML文件来侦听。点击radiobutton时就在Listview中显示相应XML文件的内容。这时候问题就来了,当我点击一个radiobutton时,照例说LISTVIEW应该会更新数据。但是并没有更新(其实后台是已经更新的了),而当我用手上下滑动一下LISTVIEW后,就能够正常显示刷新后的数据了。这样用起来用户体验很差啊。。

下面是我写的listview代码

//这是向LISTVIEW中添加XML的方法
public List<Map<String,Object>> getorderDetailData(String XMLfile){
OrderXMLReader oxr =new OrderXMLReader(XMLfile);
List<OrderDetail> allOD;
try {
allOD = oxr.getOrderDetail();
 
        for(OrderDetail od:allOD)
        {       
         //for(int i=0;i<allBI.size();i++){
         Map<String,Object> map=new HashMap<String,Object>();        
            //"BedNo", "Name","Sex","Birthday", "DateIn","DateOut","NursingClass" 
            map.put("No",od.geta());
            map.put("Sub_No",od.getb());
            map.put("Repeat_Indicator",od.getc());
            map.put("Class",od.getd());
            map.put("Start_Time",od.geti());
            map.put("Text",od.gete());
            map.put("Administration",od.getf());
            map.put("Dosage",od.getg());
            map.put("Unit",od.geth());
            map.put("Frequency",od.getj());
            map.put("Stop_Time",od.geto());
            map.put("Detail",od.getk());
            map.put("Status",od.getn());            
            ordersDetailItem.add(map);            
        }      
}
catch (Exception e) {
e.printStackTrace();
}
return ordersDetailItem;
}

// radiobutton侦听
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
radioId =checkedId;
if(checkedId == rb_long.getId()){      
getData(pat_id+"_long.xml");
}else if(checkedId == rb_short.getId()){          
getData(pat_id+"_temp.xml");
}
else if(checkedId == rb_all.getId()){      
getData(pat_id+".xml");
}else if(checkedId == rb_new.getId()){    
getData(pat_id+"_new.xml");
}else if(checkedId == rb_do.getId()){    
getData(pat_id+"_do.xml");
}else if(checkedId == rb_stop.getId()){     
getData(pat_id+"_stop.xml");
}
}

//更新方法
private void getData(final String filename) {   

final ProgressDialog   m_Dialog = ProgressDialog.show
              (
                PatientOrderDetail.this,
                "请等待...",
                "正在更新数据...", 
                true
              );
new Thread()
   { 
     public void run()
     {             
       try
       { 
        ordersDetailItem.removeAll(ordersDetailItem);
        getorderDetailData(filename);
       ordersDetailItemAdapter.notifyDataSetChanged();  

       }catch (Exception e){
           e.printStackTrace();
         }
         finally
         {                   
              m_Dialog.dismiss();}
                          
           } 
         }.start(); 
}



下面是LOGCAT中的错误信息:


12-05 14:29:15.455: E/WindowManager(11373): android.view.WindowLeaked: Activity com.doctorstation.UI.PatientMasterIndex has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41139830 that was originally added here
12-05 14:29:15.455: E/WindowManager(11373):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
12-05 14:29:15.455: E/WindowManager(11373):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
12-05 14:29:15.455: E/WindowManager(11373):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
12-05 14:29:15.455: E/WindowManager(11373):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
12-05 14:29:15.455: E/WindowManager(11373):  at android.view.Window$LocalWindowManager.addView(Window.java:537)
12-05 14:29:15.455: E/WindowManager(11373):  at android.app.Dialog.show(Dialog.java:285)
12-05 14:29:15.455: E/WindowManager(11373):  at android.app.ProgressDialog.show(ProgressDialog.java:116)
12-05 14:29:15.455: E/WindowManager(11373):  at android.app.ProgressDialog.show(ProgressDialog.java:99)
12-05 14:29:15.455: E/WindowManager(11373):  at com.doctorstation.UI.PatientMasterIndex.DownloadInfo(PatientMasterIndex.java:156)
12-05 14:29:15.455: E/WindowManager(11373):  at com.doctorstation.UI.PatientMasterIndex.onItemClick(PatientMasterIndex.java:148)
12-05 14:29:15.455: E/WindowManager(11373):  at android.widget.AdapterView.performItemClick(AdapterView.java:292)
12-05 14:29:15.455: E/WindowManager(11373):  at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
12-05 14:29:15.455: E/WindowManager(11373):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
12-05 14:29:15.455: E/WindowManager(11373):  at android.widget.AbsListView$1.run(AbsListView.java:3168)
12-05 14:29:15.455: E/WindowManager(11373):  at android.os.Handler.handleCallback(Handler.java:605)
12-05 14:29:15.455: E/WindowManager(11373):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-05 14:29:15.455: E/WindowManager(11373):  at android.os.Looper.loop(Looper.java:137)
12-05 14:29:15.455: E/WindowManager(11373):  at android.app.ActivityThread.main(ActivityThread.java:4424)
12-05 14:29:15.455: E/WindowManager(11373):  at java.lang.reflect.Method.invokeNative(Native Method)
12-05 14:29:15.455: E/WindowManager(11373):  at java.lang.reflect.Method.invoke(Method.java:511)
12-05 14:29:15.455: E/WindowManager(11373):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-05 14:29:15.455: E/WindowManager(11373):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-05 14:29:15.455: E/WindowManager(11373):  at dalvik.system.NativeStart.main(Native Method)
12-05 14:29:17.735: W/System.err(11373): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
--------------------编程问答-------------------- 你的listview怎么不写个adapter,当radiobutton的id改变时,就notifyDataSetChanged(); --------------------编程问答--------------------
引用 1 楼 yun00710 的回复:
你的listview怎么不写个adapter,当radiobutton的id改变时,就notifyDataSetChanged();

adapter写了,没有贴到那一段代码。我用的就是notifyDataSetChanged()刷新的。然后出现了上述问题。 --------------------编程问答-------------------- 你需要将要改变的数据set一次,比如要适配list<Object>,你需要在adapter中写个方法如setItemList(list<Object>);然后先set,在刷新,试试,祝你好运! --------------------编程问答--------------------
引用 3 楼 yun00710 的回复:
你需要将要改变的数据set一次,比如要适配list<Object>,你需要在adapter中写个方法如setItemList(list<Object>);然后先set,在刷新,试试,祝你好运!

好像还是不行啊。。我SET一次后数据全没了。。能解释具体点吗?
补充:移动开发 ,  Android
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,