1 /* NewsListAdapter.java
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.
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.
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/>.
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.ImageView;
23 import android.widget.TextView;
25 import java.util.ArrayList;
27 import de.dhbwloe.campusapp.R;
30 * Created by pk910 on 27.02.2016.
32 public class NewsListAdapter extends ArrayAdapter<NewsListItem> {
33 private Context context;
34 private int layoutResourceId;
35 private ArrayList<NewsListItem> data = new ArrayList<NewsListItem>();
37 public NewsListAdapter(Context context, int layoutResourceId, ArrayList<NewsListItem> data) {
38 super(context, layoutResourceId, data);
39 this.layoutResourceId = layoutResourceId;
40 this.context = context;
45 public View getView(int position, View convertView, ViewGroup parent) {
46 View row = convertView;
47 RecordHolder holder = null;
50 LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
51 row = inflater.inflate(layoutResourceId, parent, false);
53 holder = new RecordHolder(row);
56 holder = (RecordHolder) row.getTag();
59 final NewsListAdapter that = this;
60 final NewsListItem item = data.get(position);
62 holder.newsTitle.setText(item.getFormatedDate() + ": " + item.getTitle());
63 holder.newsDescription.setText(item.getDescription());
64 if(item.isDhbwNews()) {
65 holder.newsDhbwLogo.setVisibility(View.VISIBLE);
66 holder.newsStuvLogo.setVisibility(View.GONE);
68 holder.newsDhbwLogo.setVisibility(View.GONE);
69 holder.newsStuvLogo.setVisibility(View.VISIBLE);
75 static class RecordHolder {
77 TextView newsDescription;
78 ImageView newsDhbwLogo;
79 ImageView newsStuvLogo;
81 public RecordHolder(View view) {
82 this.newsTitle = (TextView) view.findViewById(R.id.newsTitleView);
83 this.newsDescription = (TextView) view.findViewById(R.id.newsDescriptionView);
85 newsDhbwLogo = (ImageView) view.findViewById(R.id.dhbwLogo);
86 newsStuvLogo = (ImageView) view.findViewById(R.id.stuvLogo);