我使用以下代码以编程方式显示与CAB
相关联的GridView
:
fileDirGridView.setMultiChoiceModeListener(gridViewMultiChoiceModeListener);
fileDirGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
fileDirGridView.setItemChecked(position, true);
现在我想要解散multiChoiceModeListener
并将一切恢复到以前的状态。为此,我使用以下代码,它总是导致StackOverFull错误。
@Override
public void onDestroyActionMode(ActionMode arg0) {
// TODO Auto-generated method stub
fileDirGridView.setChoiceMode(GridView.CHOICE_MODE_NONE);
}
Logcat
:
11-28 07:26:31.780: E/AndroidRuntime(14875): FATAL EXCEPTION: main
11-28 07:26:31.780: E/AndroidRuntime(14875): java.lang.StackOverflowError
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneWindow.java:2562)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.app.ActionBarImpl$ActionModeImpl.finish(ActionBarImpl.java:846)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView.setChoiceMode(AbsListView.java:1150)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.example.androidfilemanager.MainActivity$7.onDestroyActionMode(MainActivity.java:465)
11-28 07:26:31.780: E/AndroidRuntime(14875): at android.widget.AbsListView$MultiChoiceModeWrapper.onDestroyActionMode(AbsListView.java:6027)
11-28 07:26:31.780: E/AndroidRuntime(14875): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onDestroyActionMode(PhoneW
答案 0 :(得分:2)
我在choiceMode
内设置了onDestroyActionMode()
,导致stackoverflow
错误。所以我刚刚在同一个方法中启动了一个新线程,并在创建的线程中重置了choiceMode
。
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
Thread thread = new Thread()
{
@Override
public void run() {
fileDirGridView.clearChoices();
fileDirGridView.setChoiceMode(GridView.CHOICE_MODE_NONE);
}
};
thread.start();
}