我只是在测试这个,如果用户在显示时按下临时的“正在加载...”行,它将给出超出范围的异常。处理这个问题的最佳方法是什么?检查列表 OnItemCLickListener 上的 ID?
问候,
这是列表视图项侦听器:
实际ListView.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;
}