OSDN Git Service

Initial commit.
[gamerandomizer/gamerandomizer.git] / GameRandomizer / src / jp / sourceforge / gamerandomizer / ExpansionListAdapter.java
1 //
2 // Copyright (c) 2013  Motoyuki Kasahara
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 package jp.sourceforge.gamerandomizer;
18
19 import android.content.Context;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.ArrayAdapter;
24 import android.widget.CheckBox;
25 import android.widget.ListView;
26 import android.widget.TextView;
27
28 public class ExpansionListAdapter extends ArrayAdapter<ExpansionListItem> {
29         public ExpansionListAdapter(Context context) {
30                 super(context, 0);
31         }
32
33         @Override
34         public View getView(int position, View convertView, ViewGroup parent) {
35                 View view;
36
37                 if (convertView == null) {
38                         LayoutInflater inflater = LayoutInflater.from(getContext());
39                         view = inflater.inflate(R.layout.expansion_list, parent, false);
40                 } else {
41                         view = convertView;
42                 }
43
44                 CheckBox expansionCheckBox =
45                                 (CheckBox)view.findViewById(R.id.expansionCheckBox);
46                 ExpansionListItem item = getItem(position);
47                 expansionCheckBox.setText(item.getTitle());
48
49                 ListView listView = (ListView)parent;
50                 expansionCheckBox.setChecked(listView.isItemChecked(position));
51                 expansionCheckBox.setVisibility(View.VISIBLE);
52
53                 TextView nCardsTextView =
54                                 (TextView)view.findViewById(R.id.nCardsTextView);
55                 nCardsTextView.setText("" + item.getNCards());
56
57                 return view;
58         }
59 }