Reports Activity

Design a new layout - called Report - to look something like this:

Step 03 - 图1

This is the layout file itself:

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".Test" >
  10. <TextView
  11. android:id="@+id/reportTitle"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:layout_alignParentLeft="true"
  15. android:layout_alignParentRight="true"
  16. android:layout_alignParentTop="true"
  17. android:text="@string/reportTitle"
  18. android:textAppearance="?android:attr/textAppearanceLarge" />
  19. <ListView
  20. android:id="@+id/reportList"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:layout_alignLeft="@+id/reportTitle"
  24. android:layout_below="@+id/reportTitle" >
  25. </ListView>
  26. </RelativeLayout>

Introduce a new Class into app.activities to render this activity:

  1. package app.activities;
  2. import app.donation.R;
  3. import app.main.DonationApp;
  4. import android.app.Activity;
  5. import android.os.Bundle;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.ListView;
  8. public class Report extends Activity
  9. {
  10. ListView listView;
  11. static final String[] numbers = new String[] {
  12. "Amount, Pay method",
  13. "10, Direct",
  14. "100, PayPal",
  15. "1000, Direct",
  16. "10, PayPal",
  17. "5000, PayPal"};
  18. @Override
  19. public void onCreate(Bundle savedInstanceState)
  20. {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_report);
  23. listView = (ListView) findViewById(R.id.reportList);
  24. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, numbers);
  25. listView.setAdapter(adapter);
  26. }
  27. }

This will display a hard-coded lists of donations.

Change Donation activity to load this view when ‘Report’ selected from menu:

  1. @Override
  2. public boolean onOptionsItemSelected(MenuItem item)
  3. {
  4. switch (item.getItemId())
  5. {
  6. case R.id.menuReport : startActivity (new Intent(this, Report.class));
  7. break;
  8. }
  9. return true;
  10. }

All of this will not work until you add the activity specification to the AndroidManifest.xml file:

  1. <activity
  2. android:name="app.activities.Report"
  3. android:label="@string/donateTitle" >
  4. </activity>

Try it all now - it should load.