I would like the user to press a button.
When the onClickListener for the button is called, I would like to display a spinner until the webpage is fetched.
I don’t want to use a AsyncTask because it can only be run once and more than likely the user will click the button more than once after the first url results are retreived.
So how would I go about doing this with this onClickListener?
findIT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
item = game.getText().toString();
getUserPreference();
itemLookup.loadUrl(url);
}
});
You can still use
AsyncTask<>, you just have to create a new one each time.Otherwise you can do it yourself using
Handlers. Assuming you already haveHandlers defined for the UI and a worker thread:Personally, I think AsyncTask is a nicer solution.