0

I was just testing this, and if the user presses the temporary "loading..." row while its being shown, it will give the out of bound exception. What's the best way to deal with this? checking the id on the lists OnItemCLickListener?

regards,

Here's the listview item listener:

actualListView.setOnItemClickListener( new 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());
                    }
                }
            });

Here's the stack trace:

 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)

Its the line that gets the item at the position in the method:

parent.getItemAtPosition(position);

I've added this condition inside the onItemClick:

if(view.findViewById(R.id.loading_view)!=null){
                        //if its the loading row we wont do anything
                        return; 
                    }
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Maxrunner
  • 1,955
  • 4
  • 24
  • 41

1 Answers1

1

Tactically, you will need to filter that out yourself, by checking the position and seeing if you are on the last row.

I will look to make a patch to EndlessAdapter that will return null in this case for getItem().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hi! i've added the condition by checking the id of the loading row, it's working. – Maxrunner Jul 12 '12 at 13:27
  • Also on something unrelated, does endlessadapter has any code segment that runs before the cacheInBackGround method?i wanted to call a send a broadcast. – Maxrunner Jul 12 '12 at 13:54
  • @Maxrunner: "does endlessadapter has any code segment that runs before the cacheInBackGround method" -- not presently, though that is something that I will be working on: https://github.com/commonsguy/cwac-endless/issues/12 – CommonsWare Jul 12 '12 at 16:20