For the simplicity below is my code in onActivityResult
method inside fragment
if (requestCode==ADD_ADDRESS_REQUEST_CODE){
// do something
}else if (requestCode==COUNTRIES_REQUEST_CODE){
// do something
}
But on the else if
statement Android Studio
says
Condition requestCode==COUNTRIES_REQUEST_CODE is always false
I have more than one results in my Fragment
so I have to check them based on the request code putting else if
statements the situation is as discussed above.
If I use only if
statements like
if (requestCode==ADD_ADDRESS_REQUEST_CODE){
// do something
}
if (requestCode==COUNTRIES_REQUEST_CODE){
// do something
}
The first condition is always true even if the request code for that is not yet set. ADD_ADDRESS_REQUEST_CODE
would be set when a button in fragment
will be pressed and the COUNTRIES_REQUEST_CODE
is set on onCreateView
method of the fragment. So when Fragment shows its GUI
a toast
is showing that is inside of first condition.
Can anybody explain a bit why is that and how can I fix it. Any effort will be appreciated.
Aucun commentaire:
Enregistrer un commentaire