Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / AppSearchListAdapter.java
1 /* AppSearchListAdapter.java
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 package de.dhbwloe.campusapp.fragments;
17 import android.content.Context;
18 import android.view.LayoutInflater;
19 import android.view.View;
20 import android.view.ViewGroup;
21 import android.widget.ArrayAdapter;
22 import android.widget.TextView;
23
24 import java.util.ArrayList;
25
26 import de.dhbwloe.campusapp.R;
27
28 /**
29  * Created by pk910 on 19.01.2016.
30  */
31 public class AppSearchListAdapter  extends ArrayAdapter<AppSearchListItem> {
32     private Context context;
33     private int layoutResourceId;
34     private ArrayList<AppSearchListItem> data = new ArrayList<AppSearchListItem>();
35
36     public AppSearchListAdapter(Context context, int layoutResourceId, ArrayList<AppSearchListItem> data) {
37         super(context, layoutResourceId, data);
38         this.layoutResourceId = layoutResourceId;
39         this.context = context;
40         this.data = data;
41     }
42
43     @Override
44     public View getView(int position, View convertView, ViewGroup parent) {
45         View row = convertView;
46         RecordHolder holder = null;
47
48         if (row == null) {
49             LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
50             row = inflater.inflate(layoutResourceId, parent, false);
51
52             holder = new RecordHolder(row);
53             row.setTag(holder);
54         } else {
55             holder = (RecordHolder) row.getTag();
56         }
57
58         final AppSearchListAdapter that = this;
59         final AppSearchListItem item = data.get(position);
60
61         holder.resultTitle.setText(item.getTitle());
62         holder.resultDescription.setText(item.getDescription());
63
64         return row;
65     }
66
67     static class RecordHolder {
68         TextView resultTitle;
69         TextView resultDescription;
70
71         public RecordHolder(View view) {
72             this.resultTitle = (TextView) view.findViewById(R.id.resultTitle);
73             this.resultDescription = (TextView) view.findViewById(R.id.resultDescription);
74         }
75     }
76 }