/* * Copyright 2012 Tallinn University Centre for Educational Technology * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ee.htk.dippler.app.ArrayAdapters; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.TextView; import ee.htk.dippler.app.R; import ee.htk.dippler.app.entities.Course; public class CourseArrayAdapter extends ArrayAdapter { private int resource; private LayoutInflater layout_inflater; public CourseArrayAdapter(Context context, int resource, List objects) { super(context, resource, objects); this.resource = resource; this.layout_inflater = LayoutInflater.from(context); } @Override public View getView ( int position, View convertView, ViewGroup parent ) { ViewHolder viewHolder; if ( convertView == null ) { /* create a new view of my layout and inflate it in the row */ convertView = ( LinearLayout ) layout_inflater.inflate( resource, null ); viewHolder = new ViewHolder(); viewHolder.course_title = (TextView) convertView.findViewById(R.id.course_title); viewHolder.course_facilitator = (TextView) convertView.findViewById(R.id.course_facilitator); viewHolder.course_timeframe = (TextView) convertView.findViewById(R.id.course_timeframe); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } /* Extract the city's object to show */ Course course = getItem( position ); /* Take the TextView from layout and set the city's name */ viewHolder.course_title.setText(course.getTitle()); viewHolder.course_facilitator.setText(course.getFacilitator().getFullname()); viewHolder.course_timeframe.setText(course.getStart()+" - "+course.getEnd()); return convertView; } static class ViewHolder { TextView course_title; TextView course_facilitator; TextView course_timeframe; } }