Reputation: 3112
I made a button to delete a ListView item. It works fine on first click, but if I try to click again, it doesn't work anymore.
Here is the onClickListener code:
OnClickListener clickBtnExcluir = new OnClickListener() {
@Override
public void onClick(View v) {
if (taskManager == null) {
taskManager = new AsyncTaskManager(context);
final Entity entity = (Entity) v.getTag();
Service service = new Service();
taskManager.executeTask(service, new String[] { cod1, cod2 }, new OnAsyncTaskCompleteListener<Return>() {
@Override
public void onTaskCompleteSuccess(Return result) {
if (result == Return.YES) {
refreshList();
}
}
@Override
public void onTaskFailed(Exception cause) {
}
});
}
}
};
And here is the refreshList
method
public void refreshList() {
taskManager = new AsyncTaskManager(context);
ListService listService = new ListService();
taskManager.executeTask(listService , new String[] { cod1, "1", "0" },
new OnAsyncTaskCompleteListener<List<Entity>>() {
@Override
public void onTaskFailed(Exception cause) {
}
@Override
public void onTaskCompleteSuccess(List<Entity> result) {
listView.refreshDrawableState();
mainList = result;
notifyDataSetChanged();
}
});
}
Someone have any ideia?
Sorry by grammar mistakes.
Upvotes: 0
Views: 75
Reputation: 2325
According to your code above, the onClick will work on once {and thats what is happening}
I guess you want to check the Status of your AsyncTask before adding another async for executing:
For that please replace your if with this line
if(taskManager.getStatus()==Status.FINISHED){ //check required status
}
dont forget to check this before any other condition:
if(taskManager!=null){
}
Upvotes: 1
Reputation: 887
after the first click, taskManager is not null anymore, so you don't go through the executing code
Upvotes: 3