Refactored Report - New ‘Class’
Finally, rework the Report class to remove the hard coded values - and use a different ‘adapter’
1. public class Report extends Base {
2. private ListView listView;
4. @Override
5. public void onCreate(Bundle savedInstanceState) {
6. super.onCreate(savedInstanceState);
7. setContentView(R.layout.activity_report);
9. listView = (ListView) findViewById(R.id.reportList);
10. DonationAdapter adapter = new DonationAdapter(this, donations);
11. listView.setAdapter(adapter);
12. }
13. }
This is the new adapter - DonationAdapter. You can place this at the end of the Report class (outside the closing brace) if you like:
1. class DonationAdapter extends ArrayAdapter<Donation>
2. {
3. private Context context;
4. public List<Donation> donations;
6. public DonationAdapter(Context context, List<Donation> donations)
7. {
8. super(context, R.layout.row_donate, donations);
9. this.context = context;
10. this.donations = donations;
11. }
13. @Override
14. public View getView(int position, View convertView, ViewGroup parent)
15. {
16. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
18. View view = inflater.inflate(R.layout.row_donate, parent, false);
19. Donation donation = donations.get(position);
20. TextView amountView = (TextView) view.findViewById(R.id.row_amount);
21. TextView methodView = (TextView) view.findViewById(R.id.row_method);
23. amountView.setText("" + donation.amount);
24. methodView.setText(donation.method);
26. return view;
27. }
29. @Override
30. public int getCount()
31. {
32. return donations.size();
33. }
34. }
If all goes well - then you should be able to make donations, and then see a list of them in the report activity.
