连载:
Bundle activityArguments = new Bundle();
Stack<Class<? extends WizardStep>> wizardSteps = new Stack<Class<? extends WizardStep>>();
wizardSteps.push(CreateAlarmStep5View.class);
wizardSteps.push(CreateAlarmStep4View.class);
wizardSteps.push(CreateAlarmStep3View.class);
wizardSteps.push(CreateAlarmStep2View.class);
wizardSteps.push(CreateAlarmStep1View.class);
activityArguments.putSerializable("WizardSteps", wizardSteps);
Run Code Online (Sandbox Code Playgroud)
Deserialisation:
Stack<Class<? extends WizardStep>> wizardSteps =
(Stack<Class<? extends WizardStep>>) getIntent().getExtras().getSerializable("WizardSteps");
Run Code Online (Sandbox Code Playgroud)
例外:
12-20 23:19:45.698:E/AndroidRuntime(12145):引起:java.lang.ClassCastException:java.util.ArrayList无法强制转换为java.util.Stack
我正在为Java中的View分配一个OnClick监听器,如下所示:
public class MenuButton extends Fragment {
MenuButton self = this;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
MenuButton button = self;
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望获得对菜单按钮的引用,并将其用于我的onTouch方法中的内容(与我认为的问题无关).我知道我可以调用类的方法(例如getApplication())但我特别想要在匿名OnTouchListener中声明对象的引用.
正如你所看到的,我找到了一个解决方案!MenuButton self = this; 线.
有没有一种正确的方法可以做到这一点,还是我的奇怪解决方案唯一的方法呢?