Skip to content

Instantly share code, notes, and snippets.

@prof18
Last active January 10, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof18/ac5463e4293c09bfb9f62aebb0064791 to your computer and use it in GitHub Desktop.
Save prof18/ac5463e4293c09bfb9f62aebb0064791 to your computer and use it in GitHub Desktop.
Parser parser = new Parser();
parser.execute(urlString);
parser.onFinish(new Parser.OnTaskCompleted() {
//what to do when the parsing is done
@Override
public void onTaskCompleted(ArrayList<Article> list) {
//list is an Array List with all article's information
//set the adapter to recycler view
mAdapter = new ArticleAdapter(list, R.layout.row, MainActivity.this);
mRecyclerView.setAdapter(mAdapter);
progressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
}
//what to do in case of error
@Override
public void onError() {
runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
Toast.makeText(MainActivity.this, "Unable to load data.",
Toast.LENGTH_LONG).show();
Log.i("Unable to load ", "articles");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment