Reputation: 135
I have 2 spinner, each spinner's data loaded from database using AsyncTask
i call the AsyncTasks using this
new PopulateSpinnerA().execute();
it works if i only call one AsyncTask for one Spinner
BUT!
i have 2 Spinners, so i call the AsyncTask for each Spinner like this
new PopulateSpinnerA().execute(); // for Spinner A
new PopulateSpinnerB().execute(); // for Spinner B
I run it and my app force close
solution?
UPDATE!
i get inspiration from someone below who answer with true and false
im using a boolean (playing with true and false) to make my two spinners generated
first i make a boolean variable
Boolean SPN = false;
then i make a function to check the boolean and put it on onCreate() function
private void cek(){
if(!SPN){
new populateSpinnerA().execute();
}
if(SPN){
new populateSpinnerB().execute();
}
}
on populateSpinnerA() i just put this 2 lines to run the second spinner's AsyncTask
SPN = true;
cek();
and
BOOM!
it's done :D
Upvotes: 1
Views: 1784
Reputation: 1097
You can not have two spinner at a time. Need to use any trick in this case,
Refer below pseudo code.
postExecute(){
If(taskCompletedFlag == true){
//Code to cancel the spinner.
taskCompletedFlag = false;
}else{
taskCompledtedFlag = true;
}
}
P.S. - In case you are not aware which AsyncTask will initiate first, you can use same mechanism over there.
Upvotes: 1