Exercises

Archive of lab so far:

Exercises 1:

Consider an alternative to the NumberPicker - specifically one of the “Text Fields” controls:

Exercises - 图1

These are mostly EditView objects:

Redesign the activity to take a value from the picker or directly from a text view:

Exercises - 图2

If the number picker is set to zero, then attempt to get a number from the text view.

Here is a hint (a version of donatButonPressed that does what we want):

  1. public void donateButtonPressed (View view)
  2. {
  3. String method = paymentMethod.getCheckedRadioButtonId() == R.id.PayPal ? "PayPal" : "Direct";
  4. progressBar.setProgress(totalDonated);
  5. int donatedAmount = amountPicker.getValue();
  6. if (donatedAmount == 0)
  7. {
  8. String text = amountText.getText().toString();
  9. if (!text.equals(""))
  10. donatedAmount = Integer.parseInt(text);
  11. }
  12. totalDonated = totalDonated + donatedAmount;
  13. Log.v("Donate", amountPicker.getValue() + " donated by " + method + "\nCurrent total " + totalDonated);
  14. }

Exercise 2:

Revise the app such that when the target is achieved (10000) - then no more donations accepted, and the user is made aware of this.

Hint - here is how you can display a simple alert:

  1. Toast toast = Toast.makeText(this, "Target Exceeded!", Toast.LENGTH_SHORT);
  2. toast.show();

Exercise 3:

Show on screen at all times the total amount donated.

You will use standard TextView for this:

You already have a number of these on screen. Your layout could be revised to look like this:

Exercises - 图3

Archive of lab with Exercises: