| 1 | /* |
| 2 | * Copyright (C) 2010 Keith Kildare |
| 3 | * |
| 4 | * This file is part of SimplyDo. |
| 5 | * |
| 6 | * SimplyDo is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * SimplyDo is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with SimplyDo. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | package kdk.android.simplydo; |
| 21 | |
| 22 | import android.util.Log; |
| 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
| 25 | import android.widget.BaseAdapter; |
| 26 | import android.widget.TextView; |
| 27 | |
| 28 | public class ListPropertiesAdapter extends BaseAdapter |
| 29 | { |
| 30 | private SimplyDoActivity context; |
| 31 | private DataViewer dataViewer; |
| 32 | |
| 33 | public ListPropertiesAdapter(SimplyDoActivity context, DataViewer dataViewer) |
| 34 | { |
| 35 | this.context = context; |
| 36 | this.dataViewer = dataViewer; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | @Override |
| 41 | public int getCount() |
| 42 | { |
| 43 | return dataViewer.getListData().size(); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public Object getItem(int position) |
| 48 | { |
| 49 | return dataViewer.getListData().get(position); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public long getItemId(int position) |
| 54 | { |
| 55 | return position; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | |
| 60 | @Override |
| 61 | public View getView(final int position, View convertView, ViewGroup parent) |
| 62 | { |
| 63 | View rv = null; |
| 64 | |
| 65 | try |
| 66 | { |
| 67 | if(convertView == null) |
| 68 | { |
| 69 | rv = View.inflate(context, R.layout.list_entry, null); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | rv = convertView; |
| 74 | } |
| 75 | |
| 76 | TextView t1 = (TextView)rv.findViewById(R.id.text1); |
| 77 | ListDesc listDesc = dataViewer.getListData().get(position); |
| 78 | t1.setText(listDesc.getLabel()); |
| 79 | |
| 80 | TextView t2 = (TextView)rv.findViewById(R.id.text2); |
| 81 | t2.setText("("+ listDesc.getActiveItems() + "/" + listDesc.getTotalItems() + ")"); |
| 82 | } |
| 83 | catch(Exception e) |
| 84 | { |
| 85 | Log.e(L.TAG, "Error in getView()", e); |
| 86 | } |
| 87 | |
| 88 | return rv; |
| 89 | } |
| 90 | |
| 91 | } |