Handling Progress Updates

You can update the UI thread with background progress information by overriding the onProgressUpdate() method. Here, you grab the new score just parsed from the method parameters and insert a new row in the score TableLayout control: ©Override protected void onProgressUpdate(String... values) { if (values.length == 3) {

String scoreValue = values[0]; String scoreRank = values[1]; String scoreUserName = values[2];

insertScoreRow(table, scoreValue, scoreRank, scoreUserName); } else {

final TableRow newRow =

new TableRow(QuizScoresActivity.this); TextView noResults =

new TextView(QuizScoresActivity.this); noResults.setText(

getResources().getString(R.string.no_scores)); newRow.addView(noResults); table.addView(newRow);

The insertScoreRow() method simply creates a new TableRow control and adds it to the TableLayout control. The array of values must be passed in the same order each time. This is because of how the AsyncTask Java template works.

Was this article helpful?

0 0

Post a comment