'How to switch layouts back and forth using Square's flow library?
I am trying to use Square's flow
library to make a very simple app. The idea is that clicking a FAB will switch the screen from blue to red. Clicking the FAB again will cause it to go back to blue.
So my code for FAB's click handler looks like this:
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);
}
}
});
Going over the documentation for set( key )
, it says:
Goes to the requested key. Goes back or forward depending on whether the key is already in the History.
Also, the core part of my Dispatcher
looks like this:
@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");
}
So, is this a bug or am I doing something wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|