I have an issue with if else condition, I have fragments when I choose some options (radioButtons) and then they are pushed to activity to give a result. I'm trying to get some methods like by polymorphism but I still can't get the same result as with the if else statement. SharedPreferences could be replaced with something in this case to get the results from another fragment or not? Thanks for help.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_result);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String size = sharedPref.getString("size", "");
String activity = sharedPref.getString("activity", "");
String children = sharedPref.getString("children", "");
String dog = sharedPref.getString("dog", "");
TextView dogName = findViewById(R.id.dogName);
TextView dogName2 = findViewById(R.id.dogName2);
dogName.setText(dog);
dogName2.setText(dog);
ImageSwitcher switchImageView = findViewById(R.id.imageSwitcher);
ImageView imageView2 = findViewById(R.id.imageView2);
imageView2.setImageDrawable(null);
switchImageView.setFactory(() -> {
ImageView imageView = new ImageView(getApplicationContext());
if (size.equalsIgnoreCase("small") &&
activity.equalsIgnoreCase("lazy") &&
children.equalsIgnoreCase("like")) {
imageView.setImageResource(R.drawable.bulldog);
dogName.setText("Bulldog");
}else if (
size.equalsIgnoreCase("miniature") &&
activity.equalsIgnoreCase("light active") &&
children.equalsIgnoreCase("like")
) {
imageView.setImageResource(R.drawable.chihuahua);
dogName.setText("Chihuahua");
imageView2.setImageResource(R.drawable.york);
dogName2.setText("York");
} else if (
size.equalsIgnoreCase("miniature") &&
activity.equalsIgnoreCase("light active") &&
children.equalsIgnoreCase("no matter")
) {
imageView.setImageResource(R.drawable.york);
dogName.setText("York");
}
The if statement goes longer but i just wanted to show the method.