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;
}
Tactically, you will need to filter that out yourself, by checking the
positionand seeing if you are on the last row.I will look to make a patch to
EndlessAdapterthat will returnnullin this case forgetItem().