无尽的适配器,点击加载....行将给出异常

时间:2012-07-12 11:07:39

标签: commonsware-cwac

我只是在测试它,如果用户在显示它时按下临时“loading ...”行,它将给出超出范围的异常。处理这个问题的最佳方法是什么?检查列表OnItemCLickListener上的id?

的问候,

这是listview项侦听器:

  

actualListView.setOnItemClickListener(                   新的OnItemClickListener(){

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                    IpdmsMobileMenuItemListDTO dto=(IpdmsMobileMenuItemListDTO) parent.getItemAtPosition(position);

                    if(getView().findViewById(R.id.myprocessdetail)!=null)
                        updateProcess((MyProcessDTO) dto.getDto());
                    else{

                        mListener.onMyProcessSelected((MyProcessDTO) dto.getDto());
                    }
                }
            });

这是堆栈跟踪:

 07-12 11:35:31.558: E/AndroidRuntime(16339): FATAL EXCEPTION: main
07-12 11:35:31.558: E/AndroidRuntime(16339): java.lang.IndexOutOfBoundsException
07-12 11:35:31.558: E/AndroidRuntime(16339):    at java.util.LinkedList.get(LinkedList.java:459)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at com.commonsware.cwac.adapter.AdapterWrapper.getItem(AdapterWrapper.java:57)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.widget.HeaderViewListAdapter.getItem(HeaderViewListAdapter.java:180)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.widget.AdapterView.getItemAtPosition(AdapterView.java:740)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at sinfic.mobile.ipdms.ecrans.fragments.myprocess.MyProcessListFragment$3.onItemClick(MyProcessListFragment.java:181)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.widget.ListView.performItemClick(ListView.java:3382)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.os.Handler.handleCallback(Handler.java:587)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.os.Looper.loop(Looper.java:123)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at android.app.ActivityThread.main(ActivityThread.java:4627)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at java.lang.reflect.Method.invoke(Method.java:521)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-12 11:35:31.558: E/AndroidRuntime(16339):    at dalvik.system.NativeStart.main(Native Method)

将项目放在方法中的位置的行:

parent.getItemAtPosition(位置);

我在onItemClick中添加了这个条件:

if(view.findViewById(R.id.loading_view)!=null){
                        //if its the loading row we wont do anything
                        return; 
                    }

1 个答案:

答案 0 :(得分:1)

从战术上讲,你需要自己过滤一下,检查position并查看你是否在最后一行。

我希望a patch to EndlessAdapter能够null返回getItem() {/ 1}}。