1

我正在尝试使用 Square 的flow库来制作一个非常简单的应用程序。这个想法是单击 FAB 会将屏幕从蓝色切换到红色。再次单击 FAB 将使其变回蓝色。

所以我的 FAB 的点击处理程序代码如下所示:

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Object key = Flow.getKey(MainActivity.this);
            // why the key null when button is first clicked?
            // lets just set it to default key in case it is null
            key = (key == null) ? Screens.BLUE : key;
            // switch between red and blue screens
            // this doesnt even work.
            // we switch from blue to red but never back to blue
            if( Screens.BLUE.equals(key) ){
                Log.d("TAG", "We are currently blue");
                Log.d("TAG", "We will select red");
                Flow.get(MainActivity.this).set( Screens.RED );
            }else if(Screens.RED.equals(key)){
                Log.d("TAG", "We are currently red");
                Log.d("TAG", "We will select blue");
                Flow.get(MainActivity.this).set(Screens.BLUE);
            }
        }
    });  

浏览文档set( key ),它说:

转到请求的密钥。后退或前进取决于密钥是否已在历史记录中。

另外,我的核心部分是Dispatcher这样的:

    @LayoutRes int layout;
    if( dest.equals(Screens.BLUE) ){
        layout = R.layout.view_blue;
        Log.d("TAG","We select blue");
    }else if(dest.equals(Screens.RED)){
        layout = R.layout.view_red;
        Log.d("TAG","We select red");
    }else{
        throw new IllegalArgumentException("Unrecognized Screen");
    }

那么,这是一个错误还是我做错了什么?

4

0 回答 0